How do I apply a conditional style to a DataGrid Cell?
i'm trying to Bold a cell in the my DataGrid whenever the content of the 'Description' field is "Test" but for some reason it ain't working
the code in xaml is:
<DataGrid Margin="5" AutoGenerateColumns="True" ItemsSource="{Binding Path=.}"
Name="GrtDataGrid" MaxHeight="600"
Ver开发者_C百科ticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
Grid.Row="2" Grid.ColumnSpan="3">
<DataGrid.ItemTemplate>
<DataTemplate>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Description}" Value="Test">
<Setter Property="DataGridCell.FontWeight" Value="Bold"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</DataGrid.ItemTemplate>
</DataGrid>
what am i doing wrong ?
Try the following:
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Description}" Value="Test">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
精彩评论