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

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -