usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Linq;usingSystem.Text;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSystem.Windows.Input;usingSystem.Windows.Media;usingSystem.Windows.Media.Imaging;usingSystem.Windows.Navigation;usingSystem.Windows.Shapes;namespaceWPF data Binding {/// <summary> ///the interactive logic of MainWindow.xaml/// </summary> Public Partial classMainwindow:window {Privateperson P1 =NewPerson (); PublicMainWindow () {InitializeComponent (); } Private voidWindow_Loaded (Objectsender, RoutedEventArgs e) {P1. Age= -; P1. Name="Tony Leung"; Grid1. DataContext=P1; } Private voidButton1_Click (Objectsender, RoutedEventArgs e) {MessageBox.Show (p1). Age.tostring ()+P1. Name); } Private voidButton2_Click (Objectsender, RoutedEventArgs e) {P1. Age++; P1. Name="Takeshi Kaneshiro"; } } classperson:inotifypropertychanged { Public EventPropertyChangedEventHandler propertychanged; Private intAge ; Private stringname; Public stringName {Get { returnname; } Set { This. Name =value; if(PropertyChanged! =NULL) {propertychanged ( This,NewPropertyChangedEventArgs ("Name")); } } } Public intAge {Get { returnAge ; } Set { This. age=value; if(PropertyChanged! =NULL) {propertychanged ( This,NewPropertyChangedEventArgs (" Age")); } } } }}
Also in the foreground in the control you want to bind to write such as: text= "{Binding Name}"
Generally not directly write Textbox_1.text=p1. Name is to avoid manipulating controls directly.
ADO Data Binding