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 } } - 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; } - - - - - - - - } }