Ejemplo n.º 1
0
        public ConditionalFormat()
        {
            InitializeComponent();

            // attach cell presenter loaded/unloaded events
            grid.LoadedCellPresenter   += new EventHandler <DataGridCellEventArgs>(grid_LoadedCellPresenter);
            grid.UnloadedCellPresenter += new EventHandler <DataGridCellEventArgs>(grid_UnloadedCellPresenter);

            grid.ItemsSource = ProductDeliveryInfo.Generate(1000);
        }
Ejemplo n.º 2
0
 void grid_LoadedCellPresenter(object sender, DataGridCellEventArgs e)
 {
     if (e.Cell.Column.Name == "ExpectedDelivery")
     {
         ProductDeliveryInfo p            = (ProductDeliveryInfo)e.Cell.Row.DataItem;
         DateTime            realDelivery = p.ReadyForDelivery.AddDays(p.DeliveryDays);
         int daysDifference = p.ExpectedDelivery.Subtract(realDelivery).Days;
         if (daysDifference < -2)
         {
             e.Cell.Presenter.Background = (Brush)Resources["ProblemBrush"];
         }
         else if (daysDifference < 0)
         {
             e.Cell.Presenter.Background = (Brush)Resources["DelayBrush"];
         }
         else if (daysDifference < 1)
         {
             e.Cell.Presenter.Background = (Brush)Resources["WarningBrush"];
         }
     }
 }