WPF DataGrid Cell Color Change

DataGrid's ROW & CELL color Changing is one of most important part in our development. if you want to change Data grid specific cell Background just like:


use the xaml code for "Remaining Day" column in your Datagrid.

 <DataGridTemplateColumn Header="Remaining Day" Width="150">  
           <DataGridTemplateColumn.CellTemplate>  
                <DataTemplate>  
                     <Border x:Name="brdBroder" VerticalAlignment="Stretch" Margin="1">  
                          <TextBlock Text="{Binding RemainLeave}" Margin="3,1" x:Name="txtTextBlock"/>  
                     </Border>  
                     <DataTemplate.Triggers>  
                          <DataTrigger Binding="{Binding RemainLeave}" Value="0">  
                               <Setter TargetName="brdBroder" Property="Background" Value="Green"/>  
                               <Setter TargetName="txtTextBlock" Property="Foreground" Value="White"/>  
                          </DataTrigger>  
                     </DataTemplate.Triggers>  
                </DataTemplate>  
           </DataGridTemplateColumn.CellTemplate>  
      </DataGridTemplateColumn>  

Enjoy...

Popular posts from this blog

mvc razor textboxfor change event change another textboxfor value

WPF Crystal Report Viewer Using SAP

ASP.NET MVC razor SAP Crystal report