MVVM Foundation:アサーション失敗エラー:無効なプロパティ名
-
05-10-2019 - |
質問
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ラインに変更します。
基本クラスにはカウンターと呼ばれるプロパティがありません
編集:おそらくそれはあなたの財産が公開されていないからです
MVVM FoundationのObservableObjectのコメントは、公共財産を検証していると述べています
所属していません StackOverflow