WPF DataGrid的LoadingRow事件

        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">
   
       
   

   
        LoadingRow="gridProducts_LoadingRow_1">
           
               
               
               
               
                   
                       
                   

               

               
               
                   
                       
                           
                       

                   

               

             

       

        
   


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
{
    ///


    /// Interaction logic for MainWindow.xaml
    ///

    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)