Two way databinding with Linq to SQL in a WPF textbox or other control -
i'm trying create 2 way databind using wpf textbox control results of linq query. wrote application test this, although last row table shows on initial load, once add new row new value isn't updated in textbox. code:
xaml-code:
<window x:class="wpfapplication2test6.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"> <grid> <textbox x:name="tbtest" borderbrush="#ffcb5d5d" width="50" height="25" text="{binding source=valuep, path=processid, mode=twoway, updatesourcetrigger=propertychanged}"> </textbox> </grid> </window>
c# codebehind:
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.navigation; using system.windows.shapes; using system.runtime.compilerservices; using system.componentmodel; namespace wpfapplication2test6 { public partial class mainwindow : window { public mainwindow() { initializecomponent(); this.loaded += new routedeventhandler(window1_loaded); } void window1_loaded(object sender, routedeventargs e) { bindinglist<processupdate> processlist = new bindinglist<processupdate>(); var processid = processupdate.getnewprocessvalue().processid; tbtest.text = processid.tostring(); } } public class processupdate : inotifypropertychanged { private int pid; public event propertychangedeventhandler propertychanged; private processupdate() { wpfapplication2test6.monthlybudgetentities entity = new monthlybudgetentities(); var valuep = (from p in entity.wpftesttables select new { p.processid }).tolist().last(); pid = valuep.processid; } public static processupdate getnewprocessvalue() { return new processupdate(); } public int processid { { return pid; } set { pid = value; onpropertychanged("processid"); } } public void onpropertychanged(string pid) { propertychangedeventhandler handler = propertychanged; if (handler != null) { propertychanged(this, new propertychangedeventargs(pid.tostring())); } } }
Comments
Post a Comment