<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事件的更多相关文章

  1. WPF之DataGrid的LoadingRow事件

    利用DataGrid的LoadingRow事件,可以进行设置DataGrid的DataGridRow的属性(例如样式:背景色.前景色:是否可修改数据) 实例代码如下: private void Dat ...

  2. wpf datagrid 行双击事件

    Xaml: <DataGrid ItemsSource="{Binding SessionList}" Grid.Row="2" Grid.Column= ...

  3. wpf datagrid row height 行高自动计算使每行行高自适应文本

    wpf 的datagrid的行高 要么是Auto,要么是定值:但会带来麻烦就是每行行高都一样. 当需要按内容(主要是wrap 换行的textbox或textblock)来动态调整行高的时候,需要用到d ...

  4. WPF DataGrid 控件的运用

    WPF DataGrid 控件的运用 运行环境:Window7 64bit,.NetFramework4.61,C# 6.0: 编者:乌龙哈里 2017-02-23 参考: King Cobra 博客 ...

  5. wpf tabcontrol内的datagrid的selectionChanged事件向往传递问题

    tabcontrol 内的一个tabitem里是datagrid 当程序相应datagrid的selectionchanged事件后会向上传递到tabcontrol的selectionchanged事 ...

  6. WPF DataGrid自动生成行号

      在使用WPF进行应用程序的开发时,经常会为DataGrid生成行号,这里主要介绍一下生成行号的方法.通常有三种方法,这里主要介绍其中的两种,另一种简单提一下. 1. 直接在LoadingRow事件 ...

  7. WPF DataGrid添加编号列

    WPF DataGrid添加编号列? 第一步:<DataGridTemplateColumn Header="编号" Width="50" MinWidt ...

  8. WPF DataGrid常用属性记录

    WPF DataGrid常用属性记录 组件常用方法: BeginEdit:使DataGrid进入编辑状态. CancelEdit:取消DataGrid的编辑状态. CollapseRowGroup:闭 ...

  9. 获取wpf datagrid当前被编辑单元格的内容

    原文 获取wpf datagrid当前被编辑单元格的内容 确认修改单元个的值, 使用到datagrid的两个事件 开始编辑事件 BeginningEdit="dataGrid_Beginni ...

随机推荐

  1. IT增值服务-客户案例(三):合肥薪火科技,Java和P2P网络借贷系统开发指导

    客户整体情况: 合肥薪火科技,是安徽合肥一家主营微信开发和运营的中小企业,http://weimarket.cn/. 这家公司筹备.创立.曲折创业的经历,我一直有关注.因为2个老板,都是我的同学校友, ...

  2. ssh和SSH服务(包含隧道内容)

    ssh和SSH服务(包含隧道内容) 72.16.10.6:/etc/fstab-->/172.16.10.3:/tmp/a.txt. [root@xuexi ~]# scp 172.16.10. ...

  3. 支付宝开发之手机网站支付(H5支付)

    其实官方的文档中:https://docs.open.alipay.com/203 介绍的已经很详细了,我就实地的看文档操作了一遍,具体步骤如下: 一.创建应用 流程如下: 首先要有支付宝开放平台: ...

  4. erlang app 文件

    http://hje.iteye.com/blog/1211734 应用的概念¶ 当我们写了实现特定功能的代码之后,我们可能想将代码转成一个 应用 (application),这是可以作为一个单元启动 ...

  5. Word 2010/2013 菜单栏添加 MathType 菜单

    一般对于 office 的高级版本,比如 word 2010/2013,在手动安装 mathtype 之后,并不会再 word 的菜单栏,创建 mathtype 按钮,此时需要按照如下步骤,手动导入 ...

  6. Unable to find a single main class from the following candidates

    关于start-class,spring boot官方手册是这么说明的: The plugin rewrites your manifest, and in particular it manages ...

  7. 继承之重写prototype

    function Ff(){} //undefined Ff.prototype={a:"ss"} //Object {a: "ss"} var f1= new ...

  8. String方法总结

    蓝背景为与Array相同的方法 一.字符方法 charAt(index):返回在指定位置的字符. var str="abcdefg"; //undefined str[0] //& ...

  9. Exclusive access control to a processing resource

    A data processing system is provided with multiple processors that share a main memory. Semaphore va ...

  10. 使用nfs映射远程服务器磁盘目录

    参考:http://www.centoscn.com/CentosSecurity/SoftSecurity/2015/0408/5118.html          http://www.cnblo ...