Wednesday, 15 January 2014

c# - WPF Textbox Binding Is Not Updating When Setting Value -


I have a small program to test textbox databases and when I change the value in the text box, the code -Try to change the value of the back, the variable is updated but the textbox is not updated. I have looked around, but no solution is available, because I have seen that in order to update the text, the more I have seen, the opposite is the opposite which I want. Here's the code:

XML:

  & lt; Grid & gt; & Lt; Text box text = "{Binding FirstName, Mode = Twice, UpdateSourceTrigger = PropertyChanged}" Horizontal Alignment = "Left" Height = "23" margin = "127,37,0,0" textwapping = "wrap" vertical alignment = "top" Width = "120" /> & Lt; Text box text = "{binding last name, mode = twave, updated source = catalyst = property changes}" horizontal alignment = "left" height = "23" margin = "127,88,0,0" textwapping = "wrap" Vertical alignment = "top" width = "120" /> & Lt; TextBlock horizontal alignment = "left" margin = "28,40,0,0" textvapping = "wrap" text = "first name" vertical alignment = "top" /> & Lt; TextBlock horizontal alignment = "left" margin = "28,91,0,0" textwapping = "wrap" text = "last name" vertical alignment = "top" /> & Lt; Button x: name = "name" content = "name!" Horizontal alignment = "left" margin = "145,212,0,0" vertical alignment = "top" width = "75" click = "name_link" /> & lt; / Grid & gt;  

and my code:

  namespace wpfApplication1 {public class UIControls: INotifyPropertyChanged {public event propertyChangedEventHandler property changed; Personal string _firstName; Private string _lastName; Protected Zero Notified (string propertyName) {If (this.PropertyChanged! = Null) {PropertyChanged (New, PropertyChangedEventArgs (propertyName)); }} Public string first name {back {return_firstName; } Set {if (value! = _firstName) {_firstName = value; Inform ("first"); }}} Public String LastName {get {return _lastName; } Set {if (value! = _lastName) {_lastName = value; Inform ("last name"); }}}} Public Partial Class Main Window: Window {Public MainWindow () {InitializeComponent (); See UIControls Model = New UIControls (); this. Datacontact = view model; } Private Zero Name_Click (Object Sender, RoutedEventArgs E) {UIControls ui = New UIControls (); Ui.FirstName = "Mike"; Ui.LastName = "Smith"; }}  

}

Well you make new UIControllals Clicking every button, the new UIIContole has not been tied in the text box. Try creating a personal file that is built into the main window, something like this:

  public partial class main window: window {Private UIControls viewModel; Public Manvindo () {Initialization (); See modell = new UCentrol (); this. Datacontact = view model; } Private Zero Name_Click (Object Sender, RoutedEventArgs e) {viewModel.FirstName = "Mike"; See model.linetname = "Smith"; }  

No comments:

Post a Comment