开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜