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
|
This is one of those grey area bugs - but I figured I'd raise it anyway so that you guys know about the issue. As always, the sample I'm giving here is a much simplified case of our actual problem :) Please let me know if you have questions or other suggested workarounds.
Short summary: PropertyDescriptor does not return more than one custom property attributes when multiple are used (AllowMultiple = true) Long Description: We have some custom attributes defined as AllowMultiple = true. When we use multiple of these on a property, we can't get access to those properties through Node.Property.GetCustomAttributes due to an MS bug. This is a Microsoft issue with some known workarounds. However, Mindscape relies on and abstracts the underlying framework calls, and as such the workarounds aren't really available to users. Repro (Using the Quickstart sample) SelectedObject.xaml <Page x:Class="QuickStart.SelectedObject"
SelectedObject.xaml.cs using Mindscape.WpfPropertyGrid.SampleData;
Person.cs using System.Globalization; using System.ComponentModel; namespace Mindscape.WpfPropertyGrid.SampleData { [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] public class CustomFormattingAttribute : Attribute { string m_Reformat = "{0}"; int m_Order = int.MaxValue; public string Reformat { get { return m_Reformat; } set { m_Reformat = value; } } public int Order { get { return m_Order; } set { m_Order = value; } } } public partial class Person : Observable { ...
...
|
|
|
That thread on MSDN is missing the actual solution, which is to implement TypeId on your attribute class. Attributes that are AllowMultiple should generally implement TypeId because the TypeId is how the framework tells instances apart (it gets used as the key when the framework puts attributes in a dictionary). For example, your custom attribute could do the following:
public override object TypeId { (In fact, you could even just do return this; I think!) Note I haven't tested this in the context of the grid -- if it doesn't work, let me know. |
|
|
Also, of course, you can always manually load up the PropertyInfo:
node.DeclaringType.GetProperty(node.Property.Name); Not very efficient or elegant, but a possible fallback if the TypeId solution doesn't work for you. |
|
|
Thank you. That solved the problem perfectly. I am indebted. |
|