我想从我的datacontext和UI上绑定一个属性。
如何在texblock中显示属性地址?
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
public class Person : INotifyPropertyChanged
{
private string fullname;
public string FullName
{
get
{
return fullname;
}
set
{
fullname = value;
OnPropertChanged("FullName");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
答案 0 :(得分:0)
如果要在
中首先将Property绑定到文本块public partial class MainWindow : Window
{
private Person _myWindowModel = new Person()
public MainWindow()
{
InitializeComponent();
DataContext = _myWindowModel;
}
}
然后在WPF窗口中转到TextBlock并添加:
Text="{Binding FullName}"