문제

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

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top