wpf - Do you have a real world example of AttachedPropertyBrowsableWhenAttributePresentAttribute usage? -


i come across attachedpropertybrowsablewhenattributepresentattribute, can't think of when useful. ideals?

browsable means designer, visual studio's wpf designer named cider, shows property in designer. since attached properties not actual property of type , can applied type hard designer know when show or not show property. these attributes way developer let designer know attached property should shown in designer. in other words: browsable. specific attribute lets designer know attached property should browsable on types have specified attribute applied them.

the attached property:

public class whenattributepresenttestcontrol : grid {     public static readonly dependencyproperty showwhencustomattributepresentproperty = dependencyproperty.registerattached(       "showwhencustomattributepresent",       typeof(int),       typeof(whenattributepresenttestcontrol));      public static void setshowwhencustomattributepresent(uielement element, int value)     {         element.setvalue(showwhencustomattributepresentproperty, value);     }      [attachedpropertybrowsablewhenattributepresentattribute(typeof(mycustomattribute))]     public static int getshowwhencustomattributepresent(uielement element)     {         return (int)element.getvalue(showwhencustomattributepresentproperty);     } } 

usage example:

[mycustomattribute] public class customlabel : label { }  public class customlabelnocustomattribute : label { } 

the designer show showwhencustomattributepresent attached property in property editor customlabel, not customlabelnocustomattribute.

source: http://blogs.msdn.com/jnak/archive/2008/01/17/showing-attached-properties-in-the-cider-wpf-designer.aspx

actual usage: can not find usage of attribute in .net framework reflector.

funny side note: apparently longest type name of .net 3.0 framework


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -