• 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);
                }
            }
        }
    }

  • 相关阅读:
    cmp函数
    代码6
    代码5
    Google Code Jam在线測试题目--Alien Language
    Android ListView 和 ScrollView 冲突问题
    IOS的一个关于球碰撞的小游戏
    运用smali自己主动注入技术分析android应用程序行为
    《Pro Android Graphics》读书笔记之第二节
    单播、多播(组播)和广播的差别
    Swift闭包(Closure)
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434799.html
Copyright © 2020-2023  润新知