c# - UserControl Dependency Property design time -
i'm creating simple user control in wpf contains textblock inside button.
<usercontrol x:class="wpfexpansion.mybutton"..... > <grid > <button background="transparent" > <textblock text="{binding path=text}"/> </button> </grid> </usercontrol>
and "text" dependency property.
public partial class mybutton : usercontrol { public mybutton() { initializecomponent(); this.datacontext = this; } public string text { { return (string)getvalue(textproperty); } set { setvalue(textproperty, value); } } public static readonly dependencyproperty textproperty = dependencyproperty.register("text", typeof(string), typeof(mybutton), new propertymetadata(string.empty)); }
and use usercontrol this:
<mybutton text="test" />
the problem visual studio design not change, works in runtime.
what wrong?
i tried
datacontext="{binding relativesource={relativesource self}}"
inside uc definition, without success.
try using frameworkpropertymetadata
instead of propertymetadata
, specifying affectsrender
below, restart visual studio:
public static readonly dependencyproperty textproperty = dependencyproperty.register("text", typeof(string), typeof(mybutton), new frameworkpropertymetadata(string.empty, frameworkpropertymetadataoptions.affectsrender));
msdn documentation frameworkpropertymetadataoptions.affectsrender
says
some aspect of rendering or layout composition (other measure or arrange) affected value changes dependency property.
for other cases, there options affectsmeasure, affectsarrange, etc.
Comments
Post a Comment