首页 > Windows开发 > 详细

【Windows Phone 8】模板

时间:2014-02-12 18:15:10      阅读:383      评论:0      收藏:0      [点我收藏+]

【1.控件模板--Template】

bubuko.com,布布扣
 1     <Style x:Name="ButtonCircleStyle" TargetType="Button">
 2         <Setter Property="Width" Value="100"></Setter>
 3         <Setter Property="Height" Value="100"></Setter>
 4         <Setter Property="Template">
 5             <Setter.Value>
 6                 <ControlTemplate TargetType="Button">
 7                     <Border BorderBrush="Gray" BorderThickness="2"  CornerRadius="50" Background="{TemplateBinding Background}">
 8                         <ContentPresenter  
 9                             VerticalAlignment="Center" 
10                             HorizontalAlignment="Center"
11                             Content="{TemplateBinding Content}"/>
12                     </Border>
13                 </ControlTemplate>
14             </Setter.Value>
15         </Setter>
16     </Style>
bubuko.com,布布扣

1.这里的Template属性就是用来设置控件模板

2.ControlTemplate也要指定TargetType。

3.TemplateBinding用来绑定父控件的属性

4.ContentPresenter用来为Button内容占位(即Button的Content属性显示在该位置)

 

【2.数据模板--DataTemplate】

1     <DataTemplate x:Name="DefaultDataTemplate">
2         <TextBlock Text="{Binding}" Foreground="White"></TextBlock>
3     </DataTemplate>

1.适用于ItemsControl

2.使用时绑定ItemsControl(Listbox)的ItemTemplate属性

<ItemsControl ItemTemplate="{StaticResource DefaultDataTemplate}" ItemsSource="{Binding Names}">

 

【3.列表话控件的样式设置】

bubuko.com,布布扣
 1     <Style x:Name="DefaultItemsControlStyle" TargetType="ItemsControl">
 2         <Setter Property="Template">
 3             <Setter.Value>
 4                 <ControlTemplate>
 5                     <Border Width="440" CornerRadius="20" BorderBrush="White" BorderThickness="2" Padding="20">
 6                         <ItemsPresenter></ItemsPresenter>
 7                     </Border>
 8                 </ControlTemplate>
 9             </Setter.Value>
10         </Setter>
11         <Setter Property="ItemTemplate">
12             <Setter.Value>
13                 <DataTemplate>
14                     <TextBlock Text="{Binding}" Foreground="White"></TextBlock>
15                 </DataTemplate>
16             </Setter.Value>
17         </Setter>
18     </Style>
bubuko.com,布布扣

1.ItemsPresenter用来为ItemsControl的子项占位

2.ItemTemplate用来为ItemsControl的子项设置数据模板

 

【附WPF控件类派生关系图】

bubuko.com,布布扣

【Windows Phone 8】模板

原文:http://www.cnblogs.com/fb-boy/p/3545548.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!