WPF – How to maintain the consistency between the model and the view model in the MVVM mode?

Problem statement

I am writing a very basic WPF application to change the content of the configuration file. The data format is an XML file with a schema. I want to use it as a learning project for MVVM, so I have divided the code into two parts

> Model: C# class automatically generated from xsd.exe
>View Model: View-friendly representation of the model .
>View: Xaml and the empty code behind

I understand how View-Model makes View-binding a breeze. However, it does not leave View-Model<->The model semantics is very embarrassing ? Xsd.exe generates C# classes with multiple XML element arrays. However, at the V-VM level, you need Observable Collections.

Question:

Does this really mean Do I have to keep two completely different collection types representing the same data continuity?

What are the best practices for maintaining consistency between the model and the view model?

I am not a big expert, but I think so. The general idea is indeed spread through Binding The changes between the view and the viewModel are then propagated through events (in the Model -> ViewModel direction) or dependencies (in the other direction) to propagate the changes between the ViewModel and the Model.

I don’t know it What is the standard, but my understanding of MVVM is that ViewModel should save a reference to the model, so that when the user modifies the view, the ViewModel should call the corresponding code on the model. Conversely, the model should raise an event when it is modified, and the ViewModel Should update itself accordingly (ViewModel is the observer of the model).

Problem statement

I am writing a very basic WPF application Program to change the content of the configuration file. The data format is an XML file with a schema. I want to use it as a learning project for MVVM, so I have divided the code into two parts.

> Model: From xsd. C# class automatically generated by exe
>View Model: View-friendly representation of the model.
>View: Xaml and the empty code behind

I understand how View-Model makes View-binding become It’s easy. But, won’t you leave the View-Model<-> model semantics embarrassing? Xsd.exe generates C# classes with multiple XML element arrays. However, at the V-VM level, you need Observable Collections.

Question:

Does this really mean Do I have to keep two completely different collection types representing the same data continuity?

What are the best practices for maintaining consistency between the model and the view model?

I am not a big expert, but I think so. The general idea is indeed to propagate changes between the view and viewModel through Binding, and then through events ( In Model -> ViewModel direction) or dependent (in the other direction) to propagate changes between ViewModel and Model.

I don’t know what its standard is, but my understanding of MVVM is The ViewModel should save a reference to the model, so that when the user modifies the view, the ViewModel should call the corresponding code on the model. Conversely, the model should raise an event when it is modified, and the ViewModel should update itself accordingly (ViewModel is the observer of the model ).

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4756 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.