We have an XamDataGrid where based on a DataTrigger, we would like the foreground color to change. Recently this style has started acting up in that I could repeatedly rebind the data to the XamDataGrid and sometimes the style (based on DataTrigger) would be respected and others it wouldn't. In summary, the same row of data with the same condition that would trigger (via DataTrigger) the style would sometimes properly show the changed foreground, and others would revert to Black.
The style is defined as (Consider that InactiveInmate represents a light grey color):
<Style TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDP:CellValuePresenter}}"><Style.Triggers><DataTrigger Binding="{Binding DataItem.CustodyStatus}" Value="I"> <Setter Property="FontStyle" Value="Italic"/> <Setter Property="Foreground" Value="{StaticResource InactiveInmate}"/> <Setter Property="ForegroundStyle"> <Setter.Value> <Style> <Setter Property="TextBlock.Foreground" Value="{StaticResource InactiveInmate}"/> </Style> </Setter.Value> </Setter> </DataTrigger><MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding DataItem.CustodyStatus}" Value="I"/> <Condition Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordCellArea}}}" Value="True"/> </MultiDataTrigger.Conditions> <Setter Property="ForegroundStyle"> <Setter.Value> <Style> <Setter Property="TextBlock.Foreground" Value="{StaticResource InactiveInmate}"/> </Style> </Setter.Value> </Setter> </MultiDataTrigger> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding DataItem.CustodyStatus}" Value="I"/> <Condition Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordCellArea}}}" Value="True"/> </MultiDataTrigger.Conditions> <Setter Property="ForegroundStyle"> <Setter.Value> <Style> <Setter Property="TextBlock.Foreground" Value="{StaticResource InactiveInmate}"/> </Style> </Setter.Value> </Setter> </MultiDataTrigger> </Style.Triggers> </Style>
When SNOOPing the offending rows of data which revert to black (randomly), I noticed that the CellValuePresenter properly had been triggered to the "InactiveInmate" foreground (whether or regular or alternating row), but within it, the PART_EditorSite (ContentPresenter) was randomly appearing with TextElement.Foreground = #FF00000 (black) and thus the XamTextEditor within it inherited this black rather than the "InactiveInmate" foreground from the CellValuePresenter.
NOTE: If I would simply hit my button which would re-bind to the same data, the black and grey (InactiveInmate) rows would just randomly change as I kept banging on the button. Sometimes PART_EditorSite would respect the inherited "InactiveInmate" color from CellValuePresenter, and other times it would be Black (#FF00000).
The randomness of this occurrence leads me to believe it's not related to any potential style changing on our part elsewhere.
NOTE: When I change the FieldLayoutSettings back to HighlightAlternateRecords="False", this problem does not occur. However, as soon as I revert this property back to "True", the randomness of different rows appearing black (not respecting the style) or grey (respecting the style) starts occurring, and it occurs on both alternating rows and "regular" rows.
Resolved with ForegroundAlternateStyle:
<Setter Property="ForegroundAlternateStyle"> <Setter.Value> <Style> <Setter Property="TextElement.Foreground" Value="{StaticResource InactiveInmate}"/> </Style> </Setter.Value> </Setter>
However I cannot determine why the arbitrary swapping of styles was occuring on any row (non-alternating and alternating rows).
I have created :
<Style.Triggers> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Value="False"> <Condition.Binding> <PriorityBinding> <Binding Path="DataItem.value1" /> </PriorityBinding> </Condition.Binding> </Condition> </MultiDataTrigger.Conditions> <Setter Property="TextBlock.Foreground" Value="#727272"/> <Setter Property="TextBlock.FontStyle" Value="Italic"/> </MultiDataTrigger> </Style.Triggers>
and also have set XAMDataGrid have set HighlightAlternateRecords="False".
-----------
All the records are with DataItem.value1 = False.
But still the rows in grid are with alternate style
1. one with Black
2. and others with style mentioned above.
Any fix for this issue.
even the HighlightAlternateRecords="False". not taking effect.