- Mastering Windows Presentation Foundation
- Sheridan Yuen
- 320字
- 2021-06-24 16:49:01
View Models
The View Models can be explained easily; each View Model provides its associated View with all of the data and functionality that it requires. In some ways, they can be considered to be similar to the old Windows Forms code behind files, except that they have no direct relationship with the View that they are serving. A better analogy, if you're familiar with MVC, would be that they are similar to the Controllers in the Model-View-Controller (MVC) software architectural pattern. In fact, in his blog, John describes the MVVM pattern as being a variation of the MVC pattern.
They have two-way connections with the Model component in order to access and update the data that the Views require, and often, they transform that data in some way to make it easier to display and interact within the UI. They also have two-way connections with the Views through data binding and property change notification. In short, View Models form the bridge between the Model and the View, which otherwise have no connection to each other.
However, it should be noted that the View Models are only loosely connected to the Views and Model components through their data binding and interfaces. The beauty of this pattern enables each element to be able to function independently from each other.
To maintain the separation between the View Models and the View, we avoid declaring any properties of UI-related types in the View Model. We don't want any references to UI-related DLLs in our View Models project, and so we make use of custom IValueConverter implementations to convert them to primitive types. For example, we might convert Visibility objects from the UI to plain bool values or convert the selection of some colored Brush objects to an Enum instance that is safe to use in the View Model. We will see several examples of converters throughout this book, but for now, let's continue.
- Microsoft Exchange Server PowerShell Cookbook(Third Edition)
- Debian 7:System Administration Best Practices
- Azure IoT Development Cookbook
- Lua程序設計(第4版)
- Python程序設計
- TypeScript實戰指南
- Web性能實戰
- uni-app跨平臺開發與應用從入門到實踐
- 深入實踐DDD:以DSL驅動復雜軟件開發
- 奔跑吧 Linux內核
- C#面向對象程序設計(第2版)
- Microsoft Exchange Server 2016 PowerShell Cookbook(Fourth Edition)
- 計算機應用基礎
- Spark for Data Science
- Python編程零基礎入門