Styling a Property

Grids for WPF Forum

Posted 14 years ago by Eli Obadia
Version: 10.1.0523
Avatar
From all the properties I have the are around 3 of then that are the ones than commonly the users will be changing I would like to make them easier to recognize, how can I make them look different, for instance how can I change the background of those 3 properties that are the "most important" for the end user?

Thanks,
Eli

Comments (2)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Eli,

You can use an implicit Style for the PropertyGridDataAccessorItem type, which includes one or more triggers. In the example below, we are looking for a specific property (i.e. Text), but you can customize this as needed.
<propgrid:PropertyGrid.Resources>
    <Style TargetType="{x:Type propgrid:PropertyGridDataAccessorItem}">
        <Style.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding DataAccessorType, RelativeSource={RelativeSource Self}}" Value="Property" />
                    <Condition Binding="{Binding ValueName, RelativeSource={RelativeSource Self}}" Value="Text" />
                </MultiDataTrigger.Conditions>
                <Setter Property="Background" Value="Pink" />
            </MultiDataTrigger>
        </Style.Triggers>
    </Style>
</propgrid:PropertyGrid.Resources>
You could build a custom IValueConverter that takes a IPropertyDataAccessor and returns true (the property should be highlighted) or false (the property should not be highlighted). To do this, you'd use something like "{Binding DataContext, RelativeSource={RelativeSource Self}, Converter={StaticResource MyConverter}}" and change the value to "true".

Alternatively, you could simply return a Brush from your custom IValueConverter and bind the Background property directly. You'd replace with the MultiDataTrigger with a Trigger (with Property="DataAccessorType" Value="Property") and a single Setter that binds the Background like show in the previous paragraph. The benefit of this, is you can easily highlight various properties with different colors.


Actipro Software Support

Posted 14 years ago by Eli Obadia
Avatar
Great!
Thanks a lot,
Eli
The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.