WPF-MVVM pattern study notes 1 - MVVM concept preview

    The first version of the software work after graduation gradually drawing to a close, learning by doing can be considered able to meet the needs of the project for the time being, but still not satisfied, because there are previous WINFORM change to WPF, the feeling did not grasp the core of WPF, what tie with a good set of drawing and the like. The following new projects ready to adopt the MVVM pattern design software, pay close attention to learn a science, do not talk nonsense, directly to the question, is the article notes, so most are from the network, I would note referring URL, others hard to write articles not easy.

MVVM Introduction

   MVVM pattern is referred to as Model-View-ViewModel pattern. By the view (View), view model (the ViewModel), model (Model) consists of three parts, the structure shown in Figure 1, UI logic implemented by three parts, discrete logic and status presentation control, data and business logic. (If there is a UI designer and programmer, then the UI designer in charge of View, the program is responsible for ape ViewModel and Model, I do understand it this way, ha ha)


Division model, view, view of the model

   1. The view (View)

    View is responsible for interface and display. It is bound by the DataContext data (context data) and ViewMoel, do not interact directly with the Model. The method can be bound Behavior / Command to call the ViewModel, Command View to the ViewModel is one way to achieve by implementing the ICommand interface WPF binding offer, so that the triggering event View, ViewModel to handle the event, in order to solve the event binding function .

    2. View model (ViewModel)

    View of the model includes interface logic and model data encapsulation, Behavior / Command event response handling, and define a set of binding properties and the like. It is the bridge View and the Model, Model is an abstract, such as: Model the data format is "date" can be converted Model data is "DMY" View for display in the ViewModel.

     View of the model need to implement the interface implemented INotifyPropertyChanged WPF provided, INotifyPropertyChanged interfaces for implementing a set of attributes and change notification (Change Notifications). So that the operation made by the user on a view can be real-time notification to view the model, so that the view model object model to correct some of the business operations.

     View hidden code (Code-Behind) may contain the application logic interface logic or code that may be difficult for unit testing, depending on the circumstances should be avoided.


    3. model (Model)

    Like the MVC Model, Model encapsulate business logic for an application, and data related to the data processing method. He has the right to direct access to data, such as access to the database, Model View and does not rely on ViewModel, that is, the model does not care how the show will be or how it is operating, the model can not contain any user to use interface related logic. Model subdivided according to the actual situation in the actual development.

      The concept is simple note of it, a lot of the Internet, more than that, for the next section of code to learn.

      TrackBack URL: http: //www.cpiso.cn/jsyj/ghxx/2012/5/18/373.shtml


Published 143 original articles · won praise 161 · Views 1.21 million +

Guess you like

Origin blog.csdn.net/mybelief321/article/details/44422053