MVVM and INotifyPropertyChanged Issue

前端 未结 3 407
我寻月下人不归
我寻月下人不归 2021-01-15 04:50

I have a big problem with MVVM design. I am trying to catch every PropertyChanged of my inner nested objects, including futhermore propertchanged of their nested objects, in

3条回答
  •  走了就别回头了
    2021-01-15 05:28

    The best thing to do here is to separate the idea of a Model and a ViewModel.

    By having a ViewModel object that is flatter than the Model you can avoid this scenario. Using an automatic mapping tool like Automapper then allows you to map the Model to the ViewModel and vice versa.

    https://github.com/AutoMapper/AutoMapper/wiki/Flattening

    class MyDatViewModel : INotifyPropertyChanged
    {
        public string Str
        {
            // ... Get Set
        }
    
        public int NestedObjNum
        {
            // ... Get set
        }
    }
    
    // Configure AutoMapper
    
    Mapper.CreateMap();
    
    // Perform mapping
    
    MyDatViewModel viewModel = Mapper.Map(someData);
    

提交回复
热议问题