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 there, i want to use the propertygrid with classes which have custom attributes at their properties. i am not using ICustomTypeDescriptor or the attributes in System.ComponentModel. i was thinking about overriding PropertyNode class but it's sealed. Example: [MyAttribute(Name = "Length of item", Unit = "Meter", DefaultValue = 10)] string Length{ get; set; }
i want to use the attribute information in the propertygrid.
please any suggestions?
thanks a lot, r.
|
|
|
Where do you want to use the attributes? If you want to use them in an EditorTemplate, e.g. to create attached behaviours on a text box, you can get at them via {Binding Property.Property.AsPropertyDescriptor.Attributes} (assuming you are using a PropertyEditor, a smart editor, or a TypeEditor in WrappedValue mode, which will have to be the case for immutable types like strings). More generally, anywhere that you have a Node, you can get at the attributes of the property represented by that Node using Node.Property.AsPropertyDescriptor.Attributes. |
|
|
It almost works the way you suggested. Thanks for your help. Unfortunately the AsPropertyDescriptor is null if the Node.Source is of type Many<T>. The Properties Collection of the Many-Class is internal, so i cannot access the single IPropertyInfo. Any hints?
thanks. rf.
|
|
|
AsPropertyDescriptor is working for me in a multiple-selection scenario. Can you provide a repro that demonstrates where it's coming back as null? |
|
|
Here is a sample solution.The PropertyGrid in the middle is bound using SelectedObjects (AsPropertyDescriptor is always null, Node.Source is of type Many), the right Grid is bound to SelectedObject (AsPropertyDescriptor works). Have a look into class AttributeConverter GetAttribute.
Thank you very much. rf.
|
|
|
Hello Rainer, Thanks for the repro. However, when I run this, the converter always outputs that AsPropertyDescriptor is *not* null, even when I have a multiple selection. Either I am missing something obvious, or the issue does not occur on current builds of the grid. Could you try installing a recent nightly build of the grid (you can download nightly builds from the store) and see if that resolves the problem? Thanks! |
|
|
Hi Ivan, wow, that's it. With the new version it works. Thank you very much. Hence i'll keep it up to date. Thanks for your help. rf.
|
|