繁体   English   中英

MVVM Foundation:断言失败错误:无效的属性名称

[英]MVVM Foundation: Assertion Failed Error: Invalid Property Name

我刚刚开始使用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>

什么错误的代码? 我尝试单击“增量”按钮时出现错误

在RaisePropertyChanged行上将base更改为this。

基类没有名为Counter的属性

编辑:也许是因为你的财产受到保护而不是公开的

MVVM Foundation中的ObservableObject中的注释提到它正在验证公共属性

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM