我很難讓我的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。
我哪裏錯了?