c# - Automatic data update in WPF -


enter image description here

<window x:class="binding2.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         title="mainwindow" height="350" width="525">     <stackpanel orientation="vertical">         <stackpanel horizontalalignment="left" name="stackpanel1" verticalalignment="top" width="165" orientation="horizontal">             <textblock height="20" name="_sourcetextblock" text="source" width="67" />             <textbox height="20" name="_sourcetextbox" width="92" />         </stackpanel>         <stackpanel horizontalalignment="left" name="stackpanel2" verticalalignment="top" width="165" orientation="horizontal">             <textblock height="20" name="_desttextblock" text="destination" width="67" />             <textbox height="20" name="_desttextbox" width="92" />         </stackpanel>     </stackpanel> </window> 

i have 2 text boxes. how can program value in destination text box automatically modified based on value in source text box? example, when value in source "abc", how can make value in destination automaticaly "x" + "abc" + "x"? or, make destination number 10*source.

added

i found way result when source more 1 - bind element 2 sources

that's easy using mvvm :

public class mainwindowviewmodel : viewmodelbase {     private string _source;     public string source     {         { return _source; }         set         {             _source = value;             onpropertychanged("source");             onpropertychanged("destination");         }     }      public string destination     {         { return "x" + _source + "x"; }     }  } 

use class datacontext view, , bind 1 textbox source (twoway), , other destination (oneway):

<stackpanel orientation="vertical">     <stackpanel horizontalalignment="left" name="stackpanel1" verticalalignment="top" width="165" orientation="horizontal">         <textblock height="20" name="_sourcetextblock" text="source" width="67" />         <textbox height="20" name="_sourcetextbox" width="92" text="{binding source, mode=twoway}" />     </stackpanel>     <stackpanel horizontalalignment="left" name="stackpanel2" verticalalignment="top" width="165" orientation="horizontal">         <textblock height="20" name="_desttextblock" text="destination" width="67" />         <textbox height="20" name="_desttextbox" width="92" text="{binding destination, mode=oneway}" isreadonly="true" />     </stackpanel> </stackpanel> 

anyway, if you're building non-trivial wpf application, recommend moving mvvm pattern, in long-term app easier maintain.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -