1
我刚刚开始使用MVVM Foundation。我越来越MVVM Foundation:声明失败错误:无效的属性名称
我下面的代码:
StartViewModel
class StartViewModel : ObservableObject
{
public StartViewModel() {
_counter = 0;
}
public ICommand IncrementCommand
{
get { return _incrementCommand ?? (_incrementCommand = new RelayCommand(() => ++Counter)); }
}
protected int Counter {
get { return _counter; }
set {
_counter = value;
base.RaisePropertyChanged("Counter");
}
}
protected int _counter;
protected RelayCommand _incrementCommand;
}
StartView
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50*" />
<RowDefinition Height="250*" />
</Grid.RowDefinitions>
<Button Content="Increment" Grid.Row="0" Command="{Binding IncrementCommand}" />
<TextBlock Padding="5" Text="{Binding Counter}" Grid.Row="1" />
</Grid>
WH代码错误?当我尝试点击增加按钮
我仍然得到相同的错误。但如果因为'counter'不存在,那么为什么在示例项目中,'NumberViewModel'可以调用'base.RaisePropertyChanged(“Value”);'? – 2010-09-25 01:56:03
感谢!我注意到了! – 2010-09-25 05:40:33
谢谢。我的一个属性存在类似的问题。问题在于该房产被“保护”而不是“公共” – 2014-08-18 18:52:03