Run RaisePropertyChanged when changing Sub property - MvvmCross

I have the structure structure of the class below: when the model property changes, the RaisePropertyChanged event is not raised. Anyway, around this or do I need to smooth out a complex property inside the ViewModel?

Class ViewModel
{
   public Model model {
                   get { return _Service.GetModel();}
                   set { _Service.SetModel(); RaisePropertyChanged(() => Model);
                  }
} 

class Model
{
   public string A {get;set;}
}

Class Service
{

}
+4
source share
1 answer

I don’t think there is any easy way around.


Or you can change the model to support it INotifyPropertyChanged- for example.

class Model : MvxNotifyPropertyChanged
{
   public string A { 
        get { return _a; } 
        set { _a = value; RaisePropertyChanged(() => A); }
   }
}

I used this first approach when I used the stackoverflow library, which had models like http://stacky.codeplex.com/SourceControl/latest#trunk/source/Stacky/Entities/Answer.cs


... INotifyPropertyChanged:

class ModelWrapper : MvxNotifyPropertyChanged
{
   private readonly Model _m;
   public ModelWrapper(Model m) 
    { _m = m; }

   public string A { 
        get { return _m.A; } 
        set { _m.A = value; RaisePropertyChanged(() => A); }
   }
}

, Model - .


... , ViewModel:

class MyViewModel : MvxViewModel
{
   private readonly Model _m;
   public ModelWrapper(Model m) 
    { _m = m; }

   public string A { 
        get { return _m.A; } 
        set { _m.A = value; RaisePropertyChanged(() => A); }
   }
}

, , .


... , ViewModel Model of the View - , / Model.

+7

All Articles