Conditional Formatting of WPF DataGrid Cell Depending on DataType

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 16:05:23

I would use a DataTrigger that used a Converter to check if the object was a SolidColorBrush, and if so set the background color

Something like this:

<DataGrid.Resources>
    <Style TargetType="{x:Type DataGridCell}">
        <Style.Triggers>
            <!-- DataContext will be object for entire data row -->
            <DataTrigger Binding="{Binding MyBrushColorProperty, Converter={StaticResource IsSolidBrushColor}}" Value="True">
                <Setter Property="Background" Value="{Binding MyBrushColorProperty}" />
                <Setter Property="Content" Value="" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</DataGrid.Resources>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!