This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi How can I detect the readonly attribute of a property in a type editor.
For example a TypeEditor: <ms:TypeEditor EditedType="{x:Type vm:MyNullableDoubleField}" EditorTemplate="{StaticResource PrimitiveFieldTemplate}" />
I want to be able to detect the Readonly attribute of the properties of type MyNullableDoubleField so I can use it inside the implementation of the MyNullableDoubleField class.
John R
|
|
|
It depends on the semantics of the MyNullableDoubleField type. If MyNullableDoubleField is a value type (struct), then it is wrapped in the editor by an ObjectWrapper. You can consult ObjectWrapper.Editable (via {Binding Editable} to find out if the property is writeable. If you specifically need to know about the ReadOnlyAttribute then you can go via Node.Property.AsPropertyDescriptor to get the raw metadata. If MyNullableDoubleField is a reference type (class), then the value of the property is passed to the editor directly and the association to the property is lost. You can force it to be wrapped by setting TemplateBindingMode="WrappedValue" on the TypeEditor declaration; this allows you to use the technique described above for value types, but it means you must address the members of the class by {Binding Value.Xxx} instead of {Binding Xxx}. Another technique you could use if you have a reference type is to create a smart editor class that derives from TypeEditor but whose CanEdit method checks node.CanWrite. (The article is written in terms of lower-level editors; you can just ignore the stuff about SetContentTemplate if you're deriving from TypeEditor.) This would allow you to send read-only properties to a different editor template from read-write properties. |
|