Jonas Jensen
Jonas Jensen

Reputation: 77

Xceed Property Grid style name based on value

I want to set background of "Name2" to gray because the value is "2".

How can I achieve this?

enter image description here

I tried using DataTrigger with a converter on "PropertyItem" but I had no luck.

Upvotes: 0

Views: 636

Answers (1)

mm8
mm8

Reputation: 169228

You could define an EditorTemplate for the Name2 property:

<xctk:PropertyGrid ...>
    <xctk:PropertyGrid.EditorDefinitions>
        <xctk:EditorDefinition>
            <xctk:EditorDefinition.PropertiesDefinitions>
                <xctk:PropertyDefinition Name="Name2" />
            </xctk:EditorDefinition.PropertiesDefinitions>
            <xctk:EditorDefinition.EditorTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Value}">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Value}" Value="2">
                                        <Setter Property="Background" Value="Gray" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
                </DataTemplate>
            </xctk:EditorDefinition.EditorTemplate>
        </xctk:EditorDefinition>
    </xctk:PropertyGrid.EditorDefinitions>
</xctk:PropertyGrid>

Upvotes: 1

Related Questions