我有一個Windows應用商店項目如下:Windows應用商店綁定問題
class MyModel
{
private int _testVar;
public int TestVariable
{
get { return _testVar; }
set
{
_testVar = value;
NotifyPropertyChanged("TestVariable");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string property)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
我結合如下:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<TextBlock Text="{Binding Path=TestVariable}" />
<Button Click="Button_Click_1"></Button>
</Grid>
而後面的代碼:
MyModel thisModel = new MyModel();
public MainPage()
{
this.InitializeComponent();
thisModel.TestVariable = 0;
DataContext = thisModel;
}
由於這點,綁定似乎工作,因爲我得到的文本塊顯示爲0.但是,當我處理按鈕單擊事件如下:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
thisModel.TestVariable++;
}
我沒有看到數字增加。我在這裏錯過了什麼?
不能相信我錯過了! –