我有一个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++;
}
我没有看到数字增加。我在这里错过了什么?
不能相信我错过了! –