English 中文(简体)
传播变更通知的复合浏览模型
原标题:Composite view models propagating change notifications
  • 时间:2012-05-23 00:22:00
  •  标签:
  • c#
  • mvvm

我有一个称为“强势”的视图模型,其中引用了“强势”的级别视图模式 < /强势” 。 每个级别视图模型都代表了基本模型的等级。 我的问题是,通知“强势”操作ViewModel

我试着听了家长的“强势”财产变更

我还尝试过通过父母作为孩子的参考,然后引用一种方法,然后在链子上援引父母的提法,但同样,这似乎也很糟糕。

class OperatingViewModel : INotifyPropertyChanged
{
   LevelAListViewModel LevelACollection { get; set; }
}

class LevelAListViewModel : INotifyPropertyChanged
{
   LevelAList _model;
   LevelBListViewModel LevelBListViewModel { get; set; }
}

class LevelAViewModel : INotifyPropertyChanged
{
   LevelB _model;
   LevelBListViewModel LevelBListViewModel { get; set; }
}

class LevelBListViewModel : INotifyPropertyChanged
{
   LevelBList _model;
   ObservableCollection<LevelBViewModel> LevelBCollection { get; set; }
}

class LevelBViewModel : INotifyPropertyChanged
{
   LevelB _model;
   LevelCListViewModel LevelCListViewModel { get; set; }
}

class LevelCListViewModel : INotifyPropertyChanged
{
   LevelCList _model;
   ObservableCollection<LevelCViewModel> LevelCCollection { get; set; }
}

class LevelCViewModel : INotifyPropertyChanged
{
   LevelC _model;
   LevelDListViewModel LevelDListViewModel { get; set; }

   DateTime StartDate
   { 
       get { return _model.StartDate } 
       set 
       { 
           _model.StartDate = value; 
           OnPropertyChanged("StartDate"); 
       } 
   }

   DateTime EndDate 
   { 
       get { return _model.EndDate } 
       set 
       { 
           _model.EndDate = value;
           OnPropertyChanged("EndDate"); 
       } 
   }
}

class LevelDListViewModel : INotifyPropertyChanged
{
   LevelD _model;
   ObservableCollection<LevelDViewModel> LevelDCollection { get; set; }
}

class LevelDViewModel : INotifyPropertyChanged
{
   LevelD _model;    
   int Price
   { 
       get { return _model.Price} 
       set 
       { 
           _model.Price = value; 
           OnPropertyChanged("Price"); 
       } 
   }
}
最佳回答

最常用的四种方式是:

  1. Listening to the child s PropertyChanged event
  2. Passing a reference to a parent, and then invoking a method on the parent
  3. Passing a lambda to the children which invokes a method on the parent
  4. Using a loosely-coupled EventAggregator to publish a PropertyChanged event in the child, to which the parent subscribes. See Prism s EventAggregator for an example.

我通常会选择1或3, 始终铭记两者都可能造成内存漏漏,

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签