开发者

How do I apply a conditional style to a DataGrid Cell?

开发者 https://www.devze.com 2023-03-30 23:58 出处:网络
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

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

精彩评论

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

关注公众号