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.
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
Post a Comment