I have the following style set in my App.xaml code:
<Style TargetType="{x:Type igDP:DataRecordCellArea}"> <Setter Property="BackgroundHover" Value="Transparent" /> <Setter Property="BorderHoverBrush" Value="Transparent" /> <Setter Property="BackgroundActive" Value="{Binding Source={x:Static properties:Settings.Default}, Path=GridSelectedRowColor}" /> <Setter Property="BackgroundSelected" Value="{Binding Source={x:Static properties:Settings.Default}, Path=GridSelectedRowColor}" /> <Setter Property="BackgroundAlternate" Value="{Binding Source={x:Static properties:Settings.Default}, Path=GridAltRowBackcolor}" /> <Setter Property="BorderSelectedBrush" Value="DarkGray" /> <Setter Property="BorderAlternateBrush" Value="DarkGray" /> <Setter Property="BorderSelectedBrush" Value="DarkGray" /> <Setter Property="BorderActiveBrush" Value="DarkGray" /> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.StatusCode}" Value="I"> <Setter Property="Foreground" Value="Red" /> </DataTrigger> </Style.Triggers></Style>
The Style trigger works great when the grid is loaded, but after selecting the row with the mouse and the background changes - my foreground color is lost.
Any help would be greatly appreciated.
The GridSelectedRowColor and GridAltRowBackColor are user choices and should not affect the Foreground color (IMHO)
Hello Kenn,
Thank you for posting.
DataRecordCellArea is used primarily for styling the area around the cells. What you could do in order to change the foreground color of the record when there is a specific value in a record’s cell is applying the style to CellValuePresenter and set a style for the ForegroundHoverStyle property of the DataTrigger.
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.Name}" Value="John">
<Setter Property="Foreground" Value="Red" />
<Setter Property="ForegroundHoverStyle" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, GrayForegroundStyle}}"/>
</DataTrigger>
I have made a sample project to represent this behavior.
Please feel free to let me know if it helps you.