At the moment I am teaching my self WPF, with the MVVM model. And I'm getting it.
But one thing I don't understand. If there is a simple view:
And I have ViewModel that implements the INotifyPropertyChangedCode:<ProgressBar Height="18" Canvas.Top="89" Canvas.Left="14" Width="621" Value="{Binding ProgressPercentage, Mode=TwoWay}"/>
And there is a simple model:Code:public class ViewModelClass: INotifyPropertyChanged { private ModelClass mc; public int ProgressPercentage { get { return this.mc.ProgressPercentage;} set { if (this.mc.ProgressPercentage != value) { this.zah.ProgressPercentage = value; InvokePropertyChanged ("ProgressPercentage"); } } } public event PropertyChangedEventHandler PropertyChanged; private void InvokePropertyChanged(string propertyName) { var e = new PropertyChangedEventArgs(propertyName); PropertyChangedEventHandler changed = PropertyChanged; if (changed != null) changed(this, e); } }
The model update it's %Progress, but the ViewModel and the View don't know.Code:public class ModelClass { public int ProgressPercentage { get;set;} public void DoSomething() { this.ProgressPercentage ++; } }
If the update takes place in the ViewModel it works, because the INotifyPropertyChanged. And the Model shouldn't implement that interface (I think, because it is UI-stuff that shouldn't be in the model).
Can anyone explain how this should work?




.
Reply With Quote