WPF Propertygrid with custom sorting -


i'm looking propertygrid wpf project allows me customize ordering properties / categories listed. right i'm using extended wpf toolkits (community edition) propertygrid custompropertydescriptors. researches showed, it's not possible have custom sorting propertygrid.

is there (preferably free) solution?

ordering of properties in extended wpf toolkit can achieved decorating property propertyorderattribute attribute.

if don't want pollute poco's decorating them attributes @ design time, or order dynamic in way, it's possible add attribute @ run time creating type converter , overriding getproperties method. example, if wish maintain index order of generic ilist type:

using xceed.wpf.toolkit.propertygrid.attributes; using system.componentmodel;   public class myexpandableilistconverter<t> : expandableobjectconverter {     public override propertydescriptorcollection getproperties(itypedescriptorcontext context, object value, attribute[] attributes)     {         if (value ilist<t>)         {             ilist<t> list = value ilist<t>;              propertydescriptorcollection propdescriptions = new propertydescriptorcollection(null);             ienumerator enumerator = list.getenumerator();             int counter = -1;             while (enumerator.movenext())             {                 counter++;                 propdescriptions.add(new listitempropertydescriptor<t>(list, counter));              }             return propdescriptions;         }         else         {             return base.getproperties(context, value, attributes);         }     }         } 

with listitempropertydescriptor being defined follows:

using xceed.wpf.toolkit.propertygrid.attributes; using system.componentmodel;  public class listitempropertydescriptor<t> : propertydescriptor {     private readonly ilist<t> owner;     private readonly int index;      public listitempropertydescriptor(ilist<t> owner, int index) : base("["+ index+"]", null)     {         this.owner = owner;         this.index = index;      }      public override attributecollection attributes     {                 {             var attributes = typedescriptor.getattributes(getvalue(null), false);             //if xceed expandable object attribute not applied apply             if (!attributes.oftype<expandableobjectattribute>().any())             {                 attributes = addattribute(new expandableobjectattribute(), attributes);             }              //set xceed order attribute             attributes = addattribute(new propertyorderattribute(index), attributes);              return attributes;         }     }     private attributecollection addattribute(attribute newattribute, attributecollection oldattributes)     {         attribute[] newattributes = new attribute[oldattributes.count + 1];         oldattributes.copyto(newattributes, 1);         newattributes[0] = newattribute;          return new attributecollection(newattributes);     }      public override bool canresetvalue(object component)     {         return false;     }      public override object getvalue(object component)     {         return value;     }      private t value       => owner[index];      public override void resetvalue(object component)     {         throw new notimplementedexception();     }      public override void setvalue(object component, object value)     {         owner[index] = (t)value;     }      public override bool shouldserializevalue(object component)     {         return false;     }      public override type componenttype       => owner.gettype();      public override bool isreadonly       => false;      public override type propertytype       => value?.gettype();  } 

portions of code adapted following answer


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -