xaml で TextBlock のデータ変数を指定しようとしています。
<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");
}
}
そして MainWindow コンストラクターで値を設定しようとしています:
public MainWindow()
{
InitializeComponent();
Test = "teeest";
}
しかし、Textblock.Text は更新されませんでした...何が間違っているのでしょうか?