How to make an auto-populated Property Readonly

Grids for WPF Forum

Posted 15 years ago by Lars Reith

I would like to know if there is an easy way to set an auto-populated property to readonly in the Editor.

I am using the TypeDescriptorFactory to Browse to properties of an object dynamically set to SelectedObject. I am using a DataFilter to display only the properties of interest:

<propgrid:DataFilterGroup Operation="Or">
<propgrid:PropertyStringFilter Source="ValueName" Operation="Contains" Value="Name" />
<propgrid:PropertyStringFilter Source="ValueName" Operation="Contains" Value="Description" />

How do I configure a property, say Name, to be readonly, meaning being just displayed, nothing more.

I figured out I can use a custom PropertyEditor with a DataTemplate simply using a TextBlock. But then I have to deal a little with styling it so everything looks like the property had been readonly by default (no setter). Can't it be done easier?

My Property Editor:

<propgrid:PropertyEditor PropertyName="Name" ValueTemplate="{StaticResource SimpleTextBlock}" />

The simple DataTemplate:

<DataTemplate x:Key="SimpleTextBlock">
<Binding Path="Value" Mode="OneWay" RelativeSource="{RelativeSource AncestorType={x:Type Primitives:IPropertyDataAccessor}}" />

Best Regards!

Comments (1)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Lars,

It depends on how you are populating the PropertyGrid, but typically you would decorate your property with the ReadOnlyAttribute, like this:
public string Name {
    get; set;

Actipro Software Support

The latest build of this product (v24.1.2) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.