数据绑定:DataTemplate 与变更通知的实用指南
1. DataTemplate 基础
DataTemplate 为 UI 中特定应用程序数据源的部分或全部内容提供了一种可重复且一致的可视化表示方式。它封装了一部分 UI,可以用标准绘图基元、可用控件以及自定义控件来定义。通过将适当的绑定应用到组成元素的各种属性,DataTemplate 与后端应用程序数据源建立关联。
1.1 声明 DataTemplate
DataTemplate 可以作为资源声明,使用 x:Key 值进行引用,也可以直接在使用的地方声明。
以下是一个简单的 DataTemplate 示例,将几个 TextBlock 控件的 Text 属性绑定到 CLR 类型的属性:
<DataTemplate x:Key="dtAddress">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<
超级会员免费看
订阅专栏 解锁全文
1827

被折叠的 条评论
为什么被折叠?



