"Essential WPF - Chapter 6 Data" 阅读笔记

Chapter 6 Data


在 WPF 中, 数据绑定是一个核心的概念.


6.1 Data Principles


Most applications are built to display or create some type of data.


6.1.1 The .NET Data Model


A data model describes the contract between a source of data and the consumer of that data.

说的很玄乎, 但是在这里的意思比较简单, 指的 IEnumerable, Property 之类的数据访问接口


Because all of WPF’s data operations are based on the fundamental .NET data model, WPF controls can retrieve data from any CLR object.

这意味着 As long as data can be accessed through the CLR, it can be visualized in WPF.


6.1.2 Pervasive Binding


Binding works great as a way to keep two objects in sync, but it begins to have problems when the data types of these objects don’t match up perfectly.

Binding 是个比较好用的手段, 因此需要最大化的利用, "Full Exploitation"

To make binding truly pervasive in the framework, it was necessary to provide ways to transform data.


6.1.3 Data Transformation


WPF supports two main types of transformation: value conversion and data templates.


6.2 Resources


WPF 里面 Resources 用得还是很多的.


The lookup path for resources:

1. Element hierarchy

2. Application.Resources
3. Type theme
4. System theme


6.3 Binding Basics


Binding is simply keeping two data points in sync with each other.


Data point is an abstract concept, the idea of a single “node” of data.

A data point can be described in a variety of ways; generally it is a data source and query. For example, a property data point would be an object and a property name. The property name determines the property on the source object from which data should be retrieved.


There are two base mechanisms for value conversion: TypeConverter, which is a base mechanism that has been in .NET since version 1.0; and the new IValueConverter.


Data points and transformation are the two fundamental constructs of binding.


6.4 Binding to CLR Objects


The property name identifier for object binding has two forms: one for simple CLR properties and another for WPF’s DependencyProperty-based properties.


This optimization is useful for two reasons: first, to avoid the performance impact of using reflection; and second, to enable binding to attached properties.


6.4.1 Editing


It is important for
data sources to provide change notification to allow the binding system to respond when the data is modified.


To enable our Person object model to support change notification, we have three options: (1) implement  INotifyPropertyChanged, (2) add events that report changes to properties, or (3) create Dependency-Property-based properties.


6.5 Binding to XML



6.6 Data Templates


data templates allow us to define how a piece of data will appear.


6.6.1 Template Selection



6.7 Advanced Binding


6.7.1 Hierarchical Binding


HierarchicalDataTemplate 递归绑定树形数据结构的方式比较值得关注


6.7.2 Collection Views



6.8 Data-Driven Display


One of the more powerful things we can do with WPF is to reverse the typical relationship: The data can be the center of an application, and the UI can be secondary.

听起来很好, 不过太极端了, 可能对某些特定场合有用, 但为此增加 WPF 的复杂度值得吗?

个人分类: 笔记
上一篇"Essential WPF - Chapter 5 Visuals" 阅读笔记
下一篇"Essential WPF - Chapter 7 Actions" 阅读笔记
想对作者说点什么? 我来说一句

Essential C# 6.0 epub

2017年10月02日 50.36MB 下载

Essential C# 6.0 无水印pdf

2017年10月02日 11.64MB 下载