MVVM Fondation: Erreur Assertion Échec: Nom de la propriété non valide
-
05-10-2019 - |
Question
Je suis débutez avec MVVM Fondation. Je reçois
mes codes ci-dessous:
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>
ce qui est erroné avec le code? l'erreur apparaît lorsque je tente cliquez sur le bouton Incrémenter
La solution
base de changement à partir de la ligne RaisePropertyChanged.
La classe de base ne dispose pas d'une propriété appelée compteur
EDIT: Peut-être parce que vous propriété est protégée non publique
Les commentaires ObservableObject dans MVVM Fondation mentionne qu'il vérifie la propriété publique
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow