English 中文(简体)
如何正确界定《观点》之间的关系?
原标题:how to correctly define Model to ViewModel relation?

I trying to understand Model to ViewModel relation and I keep bumping in the same problem. Assuming we have a "Person" class with just one field:

public class Person
{
   public string Name;
}

在下一阶段,我有我的XAML艺术家,他们建立了一种能够显示一个人的用户控制,而根据MVVVER的做法,他的观点需要与VMPerson(GView-Model Person)联系起来,因此,现在我增加了另一类:

public class VMPerson : INotifyPropertyChange
{
   private Person person;

   public VMPerson():this(new Person()){}

   public VMPerson(Person person)
   {
      this.person = person;
   }

   public Name
   { get { return person.name; }
   { set { person.name = value; PropertyChange("Name"); }
}

因此,现在我几乎全心全意,但我的考试和测验组如何与我模式类别的变化有关? 如果在模式一中添加“Name”的“Name”财产,与我的观点Model类相类似,我不需要额外一层。 是否有办法保持我的《示范公约》的类别,因为现在和现在仍要通报其内部的变化。 如果没有其他办法,则使用专利权 改变机制或类似措施将在模式中加以实施,为什么我需要证书? 只是将少数“模范”类别合并成一个类别,供人们考虑吗?

I think I must be missing something in my understanding cause it seems to me according to what I described that a Model to View pattern while using the View code-behind as a controller would be better abstraction than MVVM, but I certainly not sure about that. Can someone explain to me what I am missing? thanks.

最佳回答

Putting the viewmodel code into the model is not the best idea

的确,在许多情况下,观念开始生命,看上去的是没有真正增加任何价值的超层法典,但问题是它们能够volve<>em>。

证书的作用是为便于浏览-> 指明了PropertyChanged ,而模型的作用是 概括了你的业务逻辑。 由于你的法典的功能不断提高,使财富更加丰富;在某个时候,它甚至可能比你的模式大得多。 因此,之所以作出这种区分,是为了使方便和商业逻辑部分相互完全分离,这对你的法典的维持性产生了良好的影响。

Putting the viewmodel code into the view is not the best idea

这里的理由是不同的:如果你这样做,然后需要使用另一种观点,那么,你也必须把所有逻辑同另一种观点相重复。 重复是坏的;危险是好的。

考虑到多国企业社会责任的一个重要特征是它具有可检测性,而且可检测性必然意味着至少两种类型的观点(真实的观点和模型),这种做法的必要性就变得很明显。

问题回答

浏览器的目的之一是从模型中提取数据,处理数据必须如何直观。

例如,在你的模式中,你可以有信息日报,你想视实际年龄。

在这种情况下,你应当做处理(转换日期与实际年龄,如日期)。 如今,《展望》,年刊。

In your specific case the ViewModel is just a wrapper (no processing) for the data from the model and appareantly there is no need for the Viewmodel.

为了对“观点”进行模型改动(对于不需要在证书上处理的财产),我通常在模型中采用“证明财产”的做法。 这避免了GisModel的许多精彩财产。

我的看法 我会有一些想法。

_model.PropertyChanged += PropertyChangedEventHandler(OnPropertyChangedModel);

void OnPropertyChangedModel(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
    OnPropertyChanged(e.PropertyName);
}

注意,在这种情况下,模型特性被直接送至“观点”中。

The way I look at it is as follows: - ViewModel, this is like Presenter in old MVP in a way, it will contain & join various business functionalities (like consuming of IDealService and IStaticDataService).

Model for me is very close to DataModel which simply repesents the data.

如果国家机器设备拥有太多的数据,则通常将其移入模型,并从国家机器设备中加以使用。

i.e. you could have:

public class VMPerson : INotifyPropertyChange
{
   public Person PersonItem {get; set;}

   public VMPerson()
   {
      PersonItem = new Person();
   }
}

and you can still get to Person s name in your via: {Binding PersonItem.Name}

我同意,很难证明,如果贵格人阶层确实继承了INPC。





相关问题
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. ...