How to set "IsReadOnly" on default dataTemplate

Grids for WPF Forum

Posted 1 month ago by Soojin Kim
Version: 24.1.1
Avatar

I want to set "IsReadOnly" on default dataTemplate in code.

In my code,

1. first, I make my own "dataTemplate" by data type

2. If there are no "datatemplate" that can be applied by data type, Then i don't make dataTemplate.

 In that case, I know Actipro automatically makes "Built-in DataTemplate" like this 

Built-in DataTemplates and Property Editors

3. So I want to get the type of "built-in dataTemplate", and then set "IsReadOnly" using binding. 

But, i don't know how to access the built-in dataTemplete in my code.

I try to override "AutoConfigurePropertyModel(PropertyModel, IDataFacotryRequest)" method in DataFactory class.

AutoConfigurePropertyModel(PropertyModel, IDataFactoryRequest)

But, it does not work 

Comments (3)

Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

All of our built-in property editor templates are already wired up to support IsReadOnly bindings on the property models.  The IPropertyModel.IsReadOnly property is a resolved value of the property model's IsHostReadOnly (comes from PropertyGrid.IsReadOnly) and IsValueReadOnly properties. 

If you set PropertyGrid.IsReadOnly to true, then all properties will be read-only.

Alternatively, if you only want to set specific properties as read-only, you would want to set the IPropertyModel.IsValueReadOnly property to true on appropriate property models.

Either way will update editing controls in our built-in property editors to be read-only.


Actipro Software Support

Posted 1 month ago by Soojin Kim
Avatar

Thank you for your answer !

But I would like to control the IsReadOnly by special condtion in run-time.

(ex. In property Grid Window,

- property["A"] value is setted 'X' --> property["B"] is setted ReadOnly 'True' state

- property["A"] value is setted 'Y' --> property["B"] is setted ReadOnly 'False' state

)

So, i try to use "control.SetBinding(controlType.IsReadOnly, binding)" method.

But, At built-in template, i don't know the control type because i think that the control is not instantiated.

so i can't use "SetBinding" using controlType.IsReadOnly.

How to know the control type defined in DataTemplate ??

or When/Where can i access the control that is instatiated ??

I think i need to know the time when the control defined in DataTemplate is instantiated.....)

Thank you for reading

Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Controls from data templates in WPF are not instantiated in way you can easily access them.  What you should be doing is if the IPropertyModel for property "A" has its value changed to "X", you get the IPropertyModel for property "B" and set its IsValueReadOnly property to true.  Set its IsValueReadOnly property to false when property "A" has its value changed to "Y".  As long as the DataTemplate used as a property editor for property "B" binds its read-only state to the IsReadOnly property on the IPropertyModel, which is the DataContext for the property editor DataTemplate, it should work.


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.