c# - WPF DataBinding to control properties -


i have issue whereby not receiving updates through bindings.

i have label bound extentwidth of textbox property via datacontext.

my binding works , displays value of 0 in label not update after this.

extentwidth read property, i'm not sure if affects binding in way have label binds text when set know can receive updates. (button updates text , label updated)

below code demonstrate issue.

xaml

<window x:class="testharnesses.views.window1"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="window1" height="300" width="300">     <grid>         <stackpanel>             <contentpresenter x:name="contentpresenter" content="{binding}"></contentpresenter>             <label x:name="lblextentwidth"                 content="{binding extentwidth, mode=oneway}"/>             <label x:name="lbltext"                 content="{binding text, mode=oneway}"/>             <button content="different jibber jabber" click="buttonbase_onclick"/>         </stackpanel>     </grid> </window> 

code behind

using system.windows; using system.windows.controls;  namespace testharnesses.views {     ///     <summary>         /// interaction logic window1.xaml     ///</summary>     public partial class window1 : window     {         public window1()         {             initializecomponent();             textbox tb = new textbox(){text = "jibber jabber"};             this.testtextbox = tb;         }           public textbox testtextbox         {             { return (textbox)getvalue(testtextboxproperty); }             set { setvalue(testtextboxproperty, value); }         }          // using dependencyproperty backing store testtextbox.  enables animation, styling, binding, etc...         public static readonly dependencyproperty testtextboxproperty =             dependencyproperty.register("testtextbox", typeof(textbox), typeof(window1), new propertymetadata(ontesttextboxproperty));          private static void ontesttextboxproperty(dependencyobject d, dependencypropertychangedeventargs e)         {             ((window1) d).datacontext = (textbox) e.newvalue;         }          private void buttonbase_onclick(object sender, routedeventargs e)         {             testtextbox.text = "different jibber jabber";         }       } } 

your view not being notified changes extentwidth property because extentwidth not dependencyproperty, nor textbox class implement inotifypropertychanged. also, there not appear corresponding changed event associated property.

if want update view automatically recent extentwidth you'll need listen different property/event (perhaps sizechanged event?) gets updated simultaneously.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -