public partial class Window2 : Window { public Person vmPerosn = new Person(); public Window2() { InitializeComponent(); vmPerosn.Name = "Jack Zhao"; vmPerosn.Phone = "13666666666"; vmPerosn.idNo = "110110110110110110"; //tb1.DataContext = vmPerosn; this.DataContext = vmPerosn; //< TextBox Name = "tb1" Grid.Column = "3" Text = "{Binding Path=Name}" TextWrapping = "Wrap" VerticalContentAlignment = "Center" HorizontalContentAlignment = "Stretch" /> Binding myBinding = new Binding(); myBinding.Source = vmPerosn; myBinding.Path = new PropertyPath("Phone"); myBinding.Mode = BindingMode.TwoWay; myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; BindingOperations.SetBinding(tb2, TextBox.TextProperty, myBinding); } }
标签:myBinding,Name,vmPerosn,Binding,binding,new,wpf,data,public From: https://www.cnblogs.com/zyip/p/17892038.html