Posted 16 years ago
by Lars Reith
Hi,
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:PropertyGrid.DataFilter>
<propgrid:DataFilterGroup Operation="Or">
<propgrid:PropertyStringFilter Source="ValueName" Operation="Contains" Value="Name" />
<propgrid:PropertyStringFilter Source="ValueName" Operation="Contains" Value="Description" />
</propgrid:DataFilterGroup>
</propgrid:PropertyGrid.DataFilter>
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:PropertyGrid.PropertyEditors>
<propgrid:PropertyEditor PropertyName="Name" ValueTemplate="{StaticResource SimpleTextBlock}" />
</propgrid:PropertyGrid.PropertyEditors>
The simple DataTemplate:
<DataTemplate x:Key="SimpleTextBlock">
<TextBlock>
<TextBlock.Text>
<Binding Path="Value" Mode="OneWay" RelativeSource="{RelativeSource AncestorType={x:Type Primitives:IPropertyDataAccessor}}" />
</TextBlock.Text>
</TextBlock>
</DataTemplate>
Best Regards!
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:PropertyGrid.DataFilter>
<propgrid:DataFilterGroup Operation="Or">
<propgrid:PropertyStringFilter Source="ValueName" Operation="Contains" Value="Name" />
<propgrid:PropertyStringFilter Source="ValueName" Operation="Contains" Value="Description" />
</propgrid:DataFilterGroup>
</propgrid:PropertyGrid.DataFilter>
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:PropertyGrid.PropertyEditors>
<propgrid:PropertyEditor PropertyName="Name" ValueTemplate="{StaticResource SimpleTextBlock}" />
</propgrid:PropertyGrid.PropertyEditors>
The simple DataTemplate:
<DataTemplate x:Key="SimpleTextBlock">
<TextBlock>
<TextBlock.Text>
<Binding Path="Value" Mode="OneWay" RelativeSource="{RelativeSource AncestorType={x:Type Primitives:IPropertyDataAccessor}}" />
</TextBlock.Text>
</TextBlock>
</DataTemplate>
Best Regards!