"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 的复杂度值得吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值