
Good Morning all
I need to change the Propertygrids Cell Background Color based on the Cells Value.
I got this Object bound to the DataObject of the Grid:
public class LogItemProperty
{
public LogItemProperty() { }
[Category("Entry")]
[DisplayName("Id")]
[Description("Id of the Log-Record")]
public int Id { get; set; }
[Category("Entry")]
[DisplayName("Level")]
[Description("Error Level of the Log-Record")]
public string Level { get; set; }
...
The View Model looks like that
private LogItemProperty _selectedLogItemProperty;
public LogItemProperty SelectedLogItemProperty
{
get => _selectedLogItemProperty;
set => _selectedLogItemProperty = value;
}
The Property Grid is configured like this
<grids:PropertyGrid x:Name="propGrid" IsSummaryVisible="True"
gridseditors:BuiltinPropertyEditors.IsEnabled="False"
CanClearDataObjectOnUnload="True"
DataObject="{Binding Path=SelectedLogItemProperty}" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2"
IsReadOnly="True" />
The Grid is filled with the correct Data!
Now I tried to create a Style (to be honest,my first one):
<Style x:Key="LogItemPropertyGridRowStyle"
TargetType="{x:Type grids:PropertyGridItem}">
<Style.Triggers>
<!-- Warn -->
<DataTrigger
Binding="{Binding Level, Mode=OneWay, RelativeSource={RelativeSource Self}, PresentationTraceSources.TraceLevel=High}"
Value="WARN">
<Setter
Property="Background"
Value="{StaticResource WarnLevelColor}" />
</DataTrigger>
<!-- Error -->
<DataTrigger
Binding="{Binding Level, Mode=OneWay, RelativeSource={RelativeSource Self}, PresentationTraceSources.TraceLevel=High}"
Value="ERROR">
<Setter
Property="Background"
Value="{StaticResource ErrorLevelColor}" />
</DataTrigger>
<!-- Fatal -->
<DataTrigger
Binding="{Binding Level, Mode=OneWay, RelativeSource={RelativeSource Self}, PresentationTraceSources.TraceLevel=High}"
Value="FATAL">
<Setter
Property="Background"
Value="{StaticResource FatalLevelColor}" />
</DataTrigger>
</Style.Triggers>
</Style>
But nothing happend :-(
Any help is welcome!
Kind Regards
Peter