8,757
社区成员
发帖
与我相关
我的任务
分享 public class PersonModel : INotifyPropertyChanged
{
private string _forename;
public string Forename
{
get { return _forename; }
set
{
if (value == _forename)
return;
_forename = value;
OnPropertyChanged("Forename");
}
}
}
binding 只要 设定好 源与目标,要绑定到的UIElement的某个依赖属性就ok了。 Binding binding = new Binding("DataContext.Forename");
binding.Source = this;
binding.Mode = BindingMode.TwoWay;
this.cityContext.SetBinding(TextBox.TextProperty, binding); Binding binding = new Binding("DataContext.Forename");
binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Window), 1);
binding.Mode = BindingMode.TwoWay;
this.cityContext.SetBinding(TextBox.TextProperty, binding);