c# - Data Binding Issue -
I have a big problem with TextBox to force ViewModel to bind my data in TextBlock. I have established my following XAML code as follows:
& lt; Page x: class = "digiBottle.MainPage" DataContext = "{binding source = UserProfile}" xmlns = "http: // schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http: // Schemas.microsoft.com/winfx/2006/xaml "xmlns: local =" using: digiBottle "xmlns: d =" http: //schemas.microsoft.com/expression/blend/2008 "xmlns: mc =" http : //schemas.openxmlformats.org/markup-compatibility/2006 "MC: Ignorable =" d "& gt; & Lt; Grid Background = "{ThemeResource ApplicationPageBackgroundThemeBrush}" Datacentext = "{Binding Source = User Profile}" & gt; & Lt; TextBlock HorizontalAlignment = "Left" margin = "219,72,0,0" TextWrapping = "Wrap" VerticalAlignment = "Top" height = "32" width = "232" text = "{binding userFirstName, Mode = Oneway}" / & Gt; & Lt; Text Box HorizontalAlignment = "Left" margin = "39,72,0,0" TextWrapping = "Wrap" VerticalAlignment = "Top" width = "111" text = "{userFirstName binding, UpdateSourceTrigger = PropertyChanged}" /> & Lt; / Grid & gt;
The .cs file I am trying to use as a source is defined as follows:
System use; Using System.Collections.Generic; Using System.ComponentModel; Using System.Linq; Using System.Text; System usage threading. Task; Namespace digiBottle.Model {public class UserProfile: INotifyPropertyChanged { Public Int ID {get; Set; } Public string userFirstName; Public string userListName {get; Set; } Public int age {get; Set; } The full weight of the public {receives; Set; } Public Full Height {Received; Set; } Public Date Time Registration Time {Receive; Set; } Private Event PropertyChangedEventHandler PropertyChanged; Public User Profile () {userFirstName = "First name"; } Private Wide Reciprocity Chengalated (String PropertyM) {if (this property Chengal! = Null) {this.PropertyChanged (This new property changed event event (PropertyName)); }} Public User Profile Copy () {User Profile Copy = (User Profile) Mailwordword clone (); Return copy; }}} What am I doing while attempting to bind my text box and text block to userFirstName in the UserProfile.cs source?
The first thing I notice here is that your property (Setter) The changes are not increasing. You must change the rasiporty in your property setter.
I would have written it like a private field
private string _user first name; then in the Creator
public user profile () {this._userFirstName = "first name"; } With event-raising event
public string UserFirstName {get this._userFirstName; } Set {this._userFirstName = value; This.RaisePropertyChanged ("UserFirstName"); }} and then in XAML, this bundled property "UserFirstName" along with two-way binding
& lt; TextBlock HorizontalAlignment = "Left" margin = "219,72,0,0" TextWapping = "Wrap" vertical alignment = "top" height = "32" width = "232" text = "{binding userfirstname, mode = warez}" / & Gt; & Lt; Text Box HorizontalAlignment = "Left" margin = "39,72,0,0" TextWrapping = "Wrap" VerticalAlignment = "Top" width = "111" text = "{UserFirstName, Mode = TwoWay, UpdateSourceTrigger = PropertyChanged Binding}" / & Gt;
Comments
Post a Comment