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