views:

15

answers:

1

i am just getting started with MVVM Foundation. I am getting

alt text

my codes below:

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>

whats wrong with the code? the error appears when i try click the Increment button

+1  A: 

change base to this on the RaisePropertyChanged line.

The base class does not have a property called Counter

EDIT: Perhaps it is because you property is protected not public

The comments in ObservableObject in MVVM Foundation mentions that it is verifying for public property

benPearce
i still get the same error. But if its because `Counter` does not exists then why in the example project, `NumberViewModel` can call `base.RaisePropertyChanged("Value");`?
jiewmeng
THANKS! i nv noticed that!
jiewmeng