WPF控件模板和数据模板 - 醉意人间
2017-05-24 16:21
411 查看
来自:http://www.th7.cn/Program/WPF/2011/12/21/51676.shtml ControlTemplate用于描述控件本身. 使用TemplateBinding来绑定控件自身的属性, 比如{TemplateBinding Background} DataTemplate用于描述控件的Content. 使用Binding来绑定数据对象的属性, 比如{Binding PersonName} 一般来说, ControlTemplate内有一个ContentPresenter, 这个ContentPresenter的ContentTemplate就是DataTemplate类型 Control类型 - Template属性 (ControlTemplate类型) - ContentPresenter - ContentTemplate (DataTemplate类型) ContentControl类型 - Template属性 (ControlTemplate类型) 继承自Control - ContentTemplate (DataTemplate类型) ItemsControl类型 - Template属性 (ControlTemplate类型) 继承自Control - ItemsPanel属性 (ItemsPanelTemplate类型) 指定布局容器 - ItemTemplate属性 (DateTemplate类型) 每个Item的Template <Style TargetType="Button"> <Setter Property="OverridesDefaultStyle" Value="True"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <Ellipse Fill="{TemplateBinding Background}"/> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
相关文章推荐
- WPF 深入浅出 模板(DataTemplate 数据外衣、ControlTemplate 控件外衣、ItemsPanelTemplate 项布局
- WPF中如何使用代码操作数据模板生成的控件
- WPF数据模板和控件模板
- WPF控件模板和数据模板
- WPF中如何使用代码操作数据模板生成的控件
- WPF中如何使用代码操作数据模板生成的控件
- WPF模板(一):控件模板、数据模板、面板模板
- Windows Presentation Foundation(WPF)中的数据绑定(使用XmlDataProvider作控件绑定)
- WPF中的ControlTemplate(控件模板)
- WPF中的数据模板(DataTemplate)(引用别人的文章 )
- 一款超强大的WPF图型数据展示控件
- WPF中的数据模板(DataTemplate)
- [转] 使用模板自定义 WPF 控件
- wpf datagrid 得到模板中的控件
- WPF中的控件模板(ControlTemplate)
- WPF中的控件模板(ControlTemplate)
- 一个取得数据控件模板中输入框值的类
- Windows Presentation Foundation(WPF)中的数据绑定(控件与控件值的绑定)
- WPF数据绑定(1) 绑定到控件
- WPF中的ControlTemplate(控件模板)