I'm trying to change the highlight text brush key for the selected row in my datagrid. I've tried many answers from other questions, but nothing worked for me. I set the fore- and background of the rows through a datatrigger to different colors. Now I want to keep the fore- and background color, when a row is selected. When I set the highlight brush key to transparent, the background color is the one I want. But if I set the highlight text brush key to transparent too, the text completely disappears. Is there a possibility to change that? I've tried different ways of triggering, but it didn't worked. How can I change the highlight colors for my different cases (in xaml or preferably in code behind) and not set them all to one specific color?
Example how I set the fore- and background:
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}"
<Style.Triggers>
<DataTrigger Binding="{Binding MyData}" Value="MyValue">
<Setter Property="Foreground" Value="Black"></Setter>
<Setter Property="Background" Value="LightBlue"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding MyData}" Value="MyValue">
<Setter Property="Foreground" Value="Green"></Setter>
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="FontWeight" Value="Bold"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
How I change the highlight colors:
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"></SolidColorBrush>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Transparent"></SolidColorBrush>
Its been while but off the top of my head I believe you want something like this. You set the property values to a default value then the triggers will change the default when the trigger value is matched.
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Foreground" Value="Black"></Setter>
<Setter Property="Background" Value="LightBlue"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding MyData}" Value="MyValue">
<Setter Property="Foreground" Value="Green"></Setter>
<Setter Property="Background" Value="White"></Setter>
<Setter Property="FontWeight" Value="Bold"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.