0

I am new to the MVVM pattern and thus new to MVVMCross. But I can't seem to figure out how to notify the ViewModel of changes to the model's properties. Perhaps I am understanding the pattern wrong and using the wrong architecture ?

Here is my Model class:

 public class WallModel: MvxNotifyPropertyChanged
    {
        private double _oc;

        public double oc
        {
            get { return _oc; }
            set 
            {
                _oc = value;
                RaisePropertyChanged(() => oc);
            }
        }
    }

In my ViewModel I have the following property of the WallModel class:

private WallModel _wallModel = new WallModel();

        public WallModel wallModel
        {
            get { return _wallModel; }
            set 
            { 
                SetProperty(ref _wallModel, value);
            }
        }

I can retrieve data from the model just fine so the problem is not with the binding.

What is currently happening is that the set of the oc property in the model is firing but the ViewModels set is not being fired.

What I was hoping to happen is that the RaisePropertyChanged(() => oc); would cause the ViewModles set to fire but it does not.

What does RaisePropertyChanged(() => oc); do then ? Am I misinterpreting the MVVM model and should I change my architecture?** How can I get the desired behavior?

I have tried implementing INotifyPropertyChanged manually but this to does not wprk

Zore69
  • 9
  • 4
  • *What is currently happening is that the set of the oc property in the model is firing but the ViewModels set is not being fired.* and why it should? you are not changing `wallModel` in `ViewModel` ... Why you need this? binding should works fine ... If you need this then you should register for `INotifyPropertyChanged` change in `ViewModel` ... `_wallModel.PropertyChanged += (o, e) => { /* do whatever you want ... */ }` – Selvin Sep 14 '21 at 10:05
  • The ViewModels needs to be notified as the updated Model needs to be passed to another model for processing. – Zore69 Sep 14 '21 at 13:11

1 Answers1

0

What RaisePropertyChanged(() => oc); does is notifying only the property oc of WallModel changed. Meanwhile, the WallModel on ViewModel still holds the same object of the WallModel so it assumes nothing changed.

Try to follow this guide to getting it notified.