c# - Change in dependency property from code is not displayed -


i've created button, supposed support wordwrapping. xaml code button looks this:

<button x:class="pos.touchscreen.ui.elements.touchbuttonwpf"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"               mc:ignorable="d" height="23" horizontalalignment="left" name="buttongrid" verticalalignment="top" width="75" borderbrush="#ff8a97a9" margin="4"              datacontext="{binding relativesource={relativesource self}}">     <textblock name="buttontextblock"                 horizontalalignment="stretch"                 verticalalignment="stretch"                text="{binding buttontext, mode=twoway}"                textwrapping="wrap">     </textblock>  </button> 

i've implemented property shown below:

public static readonly dependencyproperty buttontextproperty =      dependencyproperty.register("buttontext", typeof(string), typeof(touchbuttonwpf), new uipropertymetadata("button",new propertychangedcallback(onbuttontextchanged), new coercevaluecallback(oncoercebuttontext)));  private static object oncoercebuttontext(dependencyobject o, object value) {     touchbuttonwpf button = o touchbuttonwpf;     if (button != null)         return button.oncoercebuttontext((string)value);     else          return value; }  protected virtual string oncoercebuttontext(string value) {     return value; }  private static void onbuttontextchanged(dependencyobject o, dependencypropertychangedeventargs e) {     touchbuttonwpf button = o touchbuttonwpf;     if (button != null)         button.onbuttontextchanged((string)e.newvalue, (string) e.oldvalue); }  protected virtual void onbuttontextchanged(string newvalue, string oldvalue) {     this.buttontextblock.text = newvalue; }          public string buttontext {     { return (string)getvalue(buttontextproperty); }     set { setvalue(buttontextproperty, value); } } 

inserting instance of touchbuttonwpf looks this

<tse:touchbuttonwpf buttontext="ok" fontsize="16" height="77" horizontalalignment="left"x:name="buttonok" width="85" />                 

this works , button text appears correctly. when assign buttontext c# code, text not updated. i'm assigning variable shown below.

 touchbutton.buttontext = navbutton.caption; 

can tell me i'm doing wrong? note event handlers have been implemented when didn't work initially, can't figure out if these eventhandlers needed @ functionality try attain?

look forward read replies :)

your problem setting dependency property directly (this.buttontextblock.text = newvalue).

up until did this, value of this.buttontextblock.text set binding. replacing binding local value deleted binding, , text no longer respond original binding expression.

replace - this.buttontextblock.text = value;

with - this.buttontextblock.setcurrentvalue(textproperty, value);

this set value without blowing away bindings


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -