MVVM基金会:断言失败错误:无效的属性名称
-
05-10-2019 - |
题
我刚刚开始使用MVVM基金会。我正进入(状态
我的代码下面:
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>
代码怎么了?当我尝试单击“增量”按钮时,出现错误
解决方案
将基础更改为Raisepropertychanged Line。
基类没有称为计数器的属性
编辑:也许是因为您的财产受到保护而不是公共
MVVM基金会中观察者的评论提到它正在验证公共财产
不隶属于 StackOverflow