我很难让我的WPF正确使用Databinding。在XAML我有以下几点:DataBinding到TextBox不起作用
....
<TextBox Name="txt_FirstName" Text="{Binding Path=currentApplication.FirstName, UpdateSourceTrigger=PropertyChanged}" />
....
我有以下CS代码:
namespace WPF1
{
public partial class MainWindow : Window
{
personalApp currentApplication = new personalApp();
public MainWindow()
{
InitializeComponent();
}
}
}
引用以下两类:
class personalApp : INotifyPropertyChanged
{
private Person person = new Person();
public string FirstName
{
get { return person.FirstName; }
set
{
person.FirstName = value;
this.OnPropertyChanged("FirstName");
}
}
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string propName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(
this, new PropertyChangedEventArgs(propName));
}
}
class Person
{
private string firstName = "";
get { return firstName; }
set { FirstName = value; }
}
我暂停在代码并逐步检查,但是当我更新应用程序中的txt_FirstName时,它似乎永远不会设置firstName Object。
我哪里错了?