From 15e7e7bc8fcc37a3acfd93862baa2ff3d1b2ce46 Mon Sep 17 00:00:00 2001 From: "Mark A. Donohoe" Date: Mon, 19 Aug 2019 19:32:20 -0400 Subject: [PATCH 1/2] Added missing TypeId pverride Since the CategoryOrderAttribute is set to AllowMultiple-true, you must specify a TypeId to ensure uniqueness. Since this attribute should only have one instance per Category, we use CategoryValue as the key. --- .../Implementation/Attributes/CategoryOrderAttribute.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/CategoryOrderAttribute.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/CategoryOrderAttribute.cs index fff073492..0a899ba6e 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/CategoryOrderAttribute.cs +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/CategoryOrderAttribute.cs @@ -55,6 +55,13 @@ public string CategoryValue #endregion + #region TypeId + + public override object TypeId + => CategoryValue; + + #endregion TypeId + #endregion #region constructor @@ -73,4 +80,3 @@ public CategoryOrderAttribute( string categoryName, int order ) #endregion } } - From aee9e8bc9df173fb030413c82a11209b2eb25c3a Mon Sep 17 00:00:00 2001 From: "Mark A. Donohoe" Date: Mon, 19 Aug 2019 19:34:44 -0400 Subject: [PATCH 2/2] Update GetCategoryOrder to use TypeDescriptor.GetAttributes Update the logic in GetCategoryOrder to use TypeDescriptor.GetAttributes instead of Type.GetCustomAttributes as the latter doesn't take into consideration those attributes added at runtime via TypeDescriptor.AddAttributes. As such, without this change, the property grid doesn't respect dynamically added values for category ordering such as when creating custom PropertyDescriptors in a TypeConverter's GetProperties call. --- .../Implementation/ObjectContainerHelper.cs | 32 +++++-------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/ObjectContainerHelper.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/ObjectContainerHelper.cs index 2cff8874d..10ef385f1 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/ObjectContainerHelper.cs +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/ObjectContainerHelper.cs @@ -133,36 +133,20 @@ private PropertyItem CreatePropertyItem( PropertyDescriptor property, PropertyDe return propertyItem; } - private int GetCategoryOrder( object categoryValue ) + private int GetCategoryOrder(object categoryValue) { - Debug.Assert( SelectedObject != null ); + Debug.Assert(SelectedObject != null); - if( categoryValue == null ) + if (categoryValue == null) return int.MaxValue; - int order = int.MaxValue; - object selectedObject = SelectedObject; - CategoryOrderAttribute[] orderAttributes = ( selectedObject != null ) - ? ( CategoryOrderAttribute[] )selectedObject.GetType().GetCustomAttributes( typeof( CategoryOrderAttribute ), true ) - : new CategoryOrderAttribute[ 0 ]; + object selectedObject = SelectedObject; - var orderAttribute = orderAttributes - .FirstOrDefault( ( a ) => object.Equals( a.CategoryValue, categoryValue ) ); + var orderAttribute = TypeDescriptor.GetAttributes(selectedObject) + .OfType() + .FirstOrDefault(a => Equals(a.CategoryValue, categoryValue)); - if( orderAttribute != null ) - { - order = orderAttribute.Order; - } - - return order; + return orderAttribute?.Order ?? int.MaxValue; } - - - - - - - - } }