WPF DataGrid的LoadingRow事件
<Window x:Class="DataGridExam.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DataGridExam"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:ImageConverter x:Key="ImageConverter"></local:ImageConverter>
</Window.Resources>
<Grid>
<DataGrid Name="gridProducts" AutoGenerateColumns="False" FrozenColumnCount="1" LoadingRow="gridProducts_LoadingRow_1">
<DataGrid.Columns>
<DataGridTextColumn Header="Product" Width="175" Binding="{Binding Path=ModelName}"></DataGridTextColumn>
<DataGridTextColumn Header="Price" Binding="{Binding Path=UnitCost,StringFormat={}{0:C}}"></DataGridTextColumn>
<DataGridTextColumn Header="ModelNumber" Binding="{Binding Path=ModelNumber}"></DataGridTextColumn>
<DataGridTextColumn Header="Description" Width="400" Binding="{Binding Path=Description}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextWrapping" Value="Wrap"></Setter>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="CategoryID" IsReadOnly="True" Binding="{Binding Path=CategoryID}"></DataGridTextColumn>
<DataGridTemplateColumn Header="Image" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Stretch="None" Source="{Binding Path=ProductImage,Converter={StaticResource ImageConverter}}"></Image>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
using ClassLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DataGridExam
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
gridProducts.ItemsSource = StoreDB.GetProducts();
}
private void gridProducts_LoadingRow_1(object sender, DataGridRowEventArgs e)
{
Product p = (Product)e.Row.DataContext;
if (p.UnitCost >= 10)
{
e.Row.Background = new SolidColorBrush(Colors.Orange);
}
else
{
e.Row.Background = new SolidColorBrush(Colors.White);
}
}
}
}
WPF DataGrid的LoadingRow事件的更多相关文章
- WPF之DataGrid的LoadingRow事件
利用DataGrid的LoadingRow事件,可以进行设置DataGrid的DataGridRow的属性(例如样式:背景色.前景色:是否可修改数据) 实例代码如下: private void Dat ...
- wpf datagrid 行双击事件
Xaml: <DataGrid ItemsSource="{Binding SessionList}" Grid.Row="2" Grid.Column= ...
- wpf datagrid row height 行高自动计算使每行行高自适应文本
wpf 的datagrid的行高 要么是Auto,要么是定值:但会带来麻烦就是每行行高都一样. 当需要按内容(主要是wrap 换行的textbox或textblock)来动态调整行高的时候,需要用到d ...
- WPF DataGrid 控件的运用
WPF DataGrid 控件的运用 运行环境:Window7 64bit,.NetFramework4.61,C# 6.0: 编者:乌龙哈里 2017-02-23 参考: King Cobra 博客 ...
- wpf tabcontrol内的datagrid的selectionChanged事件向往传递问题
tabcontrol 内的一个tabitem里是datagrid 当程序相应datagrid的selectionchanged事件后会向上传递到tabcontrol的selectionchanged事 ...
- WPF DataGrid自动生成行号
在使用WPF进行应用程序的开发时,经常会为DataGrid生成行号,这里主要介绍一下生成行号的方法.通常有三种方法,这里主要介绍其中的两种,另一种简单提一下. 1. 直接在LoadingRow事件 ...
- WPF DataGrid添加编号列
WPF DataGrid添加编号列? 第一步:<DataGridTemplateColumn Header="编号" Width="50" MinWidt ...
- WPF DataGrid常用属性记录
WPF DataGrid常用属性记录 组件常用方法: BeginEdit:使DataGrid进入编辑状态. CancelEdit:取消DataGrid的编辑状态. CollapseRowGroup:闭 ...
- 获取wpf datagrid当前被编辑单元格的内容
原文 获取wpf datagrid当前被编辑单元格的内容 确认修改单元个的值, 使用到datagrid的两个事件 开始编辑事件 BeginningEdit="dataGrid_Beginni ...
随机推荐
- Opencv Surf算子特征提取与最优匹配
Opencv中Surf算子提取特征,生成特征描述子,匹配特征的流程跟Sift是完全一致的,这里主要介绍一下整个过程中需要使用到的主要的几个Opencv方法. 1. 特征提取 特征提取使用SurfFea ...
- PHP/HTML混写的四种方式总结
PHP/HTML混写的四种方式总结 一.总结 一句话总结: 注意点: 1.双引号里面解析变量:echo "$Content" 2.HEREDOC和NOWDOC的关系:类似于双引号包 ...
- javaScript显示实时时间输出
实时时间输出 <script> function getDateTime(){ var a = new Date(); var year = a.getFullYear(); var mo ...
- 【codeforces 791D】 Bear and Tree Jumps
[题目链接]:http://codeforces.com/contest/791/problem/D [题意] 你可以从树上的节点一次最多走k条边. (称为跳一次); 树为无权树; 然后问你任意两点之 ...
- 《大话操作系统——扎实project实践派》(8.2)(除了指令集.完)
- URAL 1577. E-mail(简单二维dp)
给你两个子串,让你找出来一个最短的字符串包括这两个子串,输出最多的子串有多少种. 类似于最长公共子序列,相等的话长度+1,不想等的话比較长度,使用长度小的. 1577. E-mail Time lim ...
- 多线程编程 CreateThread(解释了TContext)
function CreateThread( lpThreadAttributes: Pointer; {安全设置} dwStackSize: DWORD; ...
- C# 调用PowerShell方法
PowerShell应为编写和运行都很方便,所以为了重复利用,经常写了一些小方法或者PS代码片段.使用的时候可能会很难找到自己想要的那个方法,如果要是有一个界面把这些代码管理起来并且调用,那就很爽了 ...
- less循环写css工具类
//margin-right=================.mr(100); .mr(@n, @i: 1) when (@i =< @n) { .mr-@{i} { margin-right ...
- 初探js
第一章 1.JS的位置 1-1.行间 1-2.内嵌 1-3.外联 2.JS的标签位置 页面中的代码在一般情况下会按从上到下的顺序,从左往右的顺序执行. 因此当JS放在了元素上面的时候,就不能正常执 ...