数据绑定Data binding

数据绑定是你的应用 UI 用来显示数据的一种方法,可以选择与该数据保持同步。Data binding is a way for your app's UI to display data, and optionally to stay in sync with that data. 借助数据绑定,你可以将关注的数据从关注的 UI 中分离开来,从而形成一个更简易的概念模型,并且使应用具有更好的可读性、可测试性和可维护性。Data binding allows you to separate the concern of data from the concern of UI, and that results in a simpler conceptual model as well as better readability, testability, and maintainability of your app. 在标记中,你既可以选用 {x:Bind} 标记扩展,也可以选用 {Binding} 标记扩展In markup, you can choose to use either the {x:Bind} markup extension or the {Binding} markup extension. 还可以在同一应用中(甚至是同一 UI 元素上)混合使用这两个标记扩展。And you can even use a mixture of the two in the same app—even on the same UI element. {x:Bind} 是 Windows 10 的新增内容,并且具备更好的性能。{x:Bind} is new for Windows 10 and it has better performance.

主题Topic 说明Description
数据绑定概述Data binding overview 本主题介绍了如何在通用 Windows 平台 (UWP) 应用中将控件(或其他 UI 元素)绑定到单个项目,或者将项目控件绑定到项目集合。This topic shows you how to bind a control (or other UI element) to a single item or bind an items control to a collection of items in a Universal Windows Platform (UWP) app. 此外,我们还介绍了如何控制项的呈现、基于所选内容实现详细信息视图,以及转换数据以供显示。In addition, we show how to control the rendering of items, implement a details view based on a selection, and convert data for display. 有关更多详细信息,请参阅深入了解数据绑定For more detailed info, see Data binding in depth.
深入了解数据绑定Data binding in depth 本主题详细介绍数据绑定功能。This topic describes data binding features in detail.
设计面图上以及用于原型制作的示例数据Sample data on the design surface, and for prototyping 为了使你的控件填充 Visual Studio 设计器中的数据(以便你可以处理应用的布局、模板和其他视觉属性),你可以通过各种方式使用设计时示例数据。In order to have your controls populated with data in the Visual Studio designer (so that you can work on your app's layout, templates, and other visual properties), there are various ways in which you can use design-time sample data. 如果你正要生成一个草图(或原型)应用,则示例数据可能真的非常有用而且节省时间。Sample data can also be really useful and time-saving if you're building a sketch (or prototype) app. 你可以在运行时在草图或原型中使用示例数据来阐明你的想法,而无需连接到真实且实时的数据。You can use sample data in your sketch or prototype at run-time to illustrate your ideas without going as far as connecting to real, live data.
绑定分层数据和创建大纲/细节视图Bind hierarchical data and create a master/details view 你可以通过将项目控件绑定到 CollectionViewSource 实例(它们绑定在同一个链中),从而生成分层数据的多级主视图/详细信息视图(也称为列表详细信息视图)。You can make a multi-level master/details (also known as list-details) view of hierarchical data by binding items controls to CollectionViewSource instances that are bound together in a chain.
数据绑定和 MVVMData binding and MVVM 本主题介绍了模型-视图-视图模型 (MVVM) UI 体系结构设计模式。This topic describes the Model-View-ViewModel (MVVM) UI architectural design pattern. 数据绑定是 MVVM 的核心,并且在 UI 与非 UI 代码之间实现了松散耦合。Data binding is at the core of MVVM, and enables loose coupling between UI and non-UI code.