資料繫結Data binding

資料繫結可讓您的 App 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. 您甚至可以在相同的 app 中將兩者混用 (甚至在相同的 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 設計工具中讓您的控制項能夠填入資料 (讓您能夠在 app 的配置、範本及其他視覺化屬性上運作),系統提供了各種不同方式,讓您可以使用設計階段的範例資料。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. 如果您正在建置草圖 (或原型) app,則範例資料也可以是非常實用且省時的。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 本主題說明 Model View ViewModel (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.