1
我試圖在XAML我TextBlock的指定數據的變量:OnPropertyChanged和XAML
<TextBlock Name="Test11" Text="{Binding Path=Test}"></TextBlock>
我使用OnPropertyChanged它:
public partial class MainWindow : Window, INotifyPropertyChanged
private string _test;
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
public string Test
{
get
{
return _test;
}
set
{
_test = value;
OnPropertyChanged("Test");
}
}
,並試圖在主窗口的構造函數來設置值:
public MainWindow()
{
InitializeComponent();
Test = "teeest";
}
但Textblock.Text沒有更新...... 我做錯了什麼?