控件模版的概念

Windows Phone中每一个控件都有一个默认的模版,用于描述控件的内部组成结构和外观样式

相对于原本的样式外观操作,自定义模版的可自定义性更强

最基本的重写控件模版

     <Grid>
<!--Button按钮居中对齐-->
<Button HorizontalAlignment="Center">
<!--原生控件模版设置的就是Template属性-->
<Button.Template>
<!--控件模版类型-->
<ControlTemplate>
<!--Border本身支持圆角-->
<Border
BorderBrush="White"
BorderThickness="3"
CornerRadius="10,20,10,10">
<TextBlock
Text="Button"
TextAlignment="Center"
VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>

BorderBrush 颜色  BorderThickness 边框宽度  CornerRadius 四个圆角的弧度

Text 内容  TextAlignment 水平对齐方式  VerticalAlignment 垂直对齐方式

绑定属性和重用(自定义控件模版)

     <Page.Resources>
<!--圆角Button模版-->
<ControlTemplate x:Key="CornerButton" TargetType="Button">
<!--Border本身支持圆角-->
<Border
Background="{TemplateBinding Button.Background}"
BorderBrush="{TemplateBinding Button.BorderBrush}"
BorderThickness="{TemplateBinding Button.BorderThickness}"
CornerRadius="10,20,10,10">
<!--TemplateBinding是用来在模版中绑定当前控件属性-->
<TextBlock
Text="{TemplateBinding Button.Content}"
TextAlignment="Center"
VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
<!--统一所有按钮-->
<Style TargetType="Button">
<Setter Property="Template" Value="{StaticResource CornerButton}"/>
</Style>
</Page.Resources>
<Grid>
<!--圆角Button模版,资源引用-->
<Button
Content="Button"
Background="Aqua"
BorderBrush="HotPink"
BorderThickness="15"
HorizontalAlignment="Center"
Template="{StaticResource CornerButton}">
</Button>
</Grid>

图标按钮展示内容

Button派生自ContentControl,所有ContentControl都是由ContentPersenter展示Content属性
     <Grid>
<Button>
<Button.Content>
<SymbolIcon Symbol="Accept"/>
</Button.Content>
<Button.Template>
<ControlTemplate>
<Border
BorderBrush="White"
BorderThickness="3" CornerRadius="10">
<ContentPresenter/>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>

Windows Phone 四、控件模版的更多相关文章

  1. 使用代码浏览WPF控件模版

    纯代码创建,不需要创建界面,创建WPF工程后,直接复制代码就可以使用. 当你手头没有Blend,又不记得以下这段代码,但是又想浏览控件模版的时候,就可以直接复制拿来用了. public partial ...

  2. 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog

    [源码下载] 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog 作者:webabcd 介绍背水一战 Windows 10 之 控 ...

  3. 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu

    [源码下载] 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹 ...

  4. 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout

    [源码下载] 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout 作者:webabcd 介绍背水一战 Windows 10 之 ...

  5. 背水一战 Windows 10 (34) - 控件(进度类): RangeBase, Slider, ProgressBar, ProgressRing

    [源码下载] 背水一战 Windows 10 (34) - 控件(进度类): RangeBase, Slider, ProgressBar, ProgressRing 作者:webabcd 介绍背水一 ...

  6. 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch

    [源码下载] 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch 作者:webabcd 介绍背水一 ...

  7. 背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox

    [源码下载] 背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(选择类) Sel ...

  8. 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButton, AppBarButton, AppBarToggleButton

    [源码下载] 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButt ...

  9. 背水一战 Windows 10 (30) - 控件(文本类): AutoSuggestBox

    [源码下载] 背水一战 Windows 10 (30) - 控件(文本类): AutoSuggestBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(文本类) AutoSug ...

随机推荐

  1. CodeForces 519B A and B and Compilation Errors

    B. A and B and Compilation Errors time limit per test 2 seconds memory limit per test 256 megabytes ...

  2. jQuery对数据和对象的操作

    <script type="text/javascript" src="jquery-1.8.2.min.js"></script> & ...

  3. js中addEventListener中第3个参数

    addEventListener中的第三个参 数是useCapture, 一个bool类型.当为false时为冒泡获取(由里向外),true为capture方式(由外向里). <div id=& ...

  4. css 一些灵动性的小方法

    CSS: 1.当鼠标放到一个图片上的时候,他会给你显示一些图片的信息或者是一些其他的信息. <!DOCTYPE html> <html lang="en"> ...

  5. 从头到尾彻底理解KMP

    从头到尾彻底理解KMP 作者:July 时间:最初写于2011年12月,2014年7月21日晚10点 全部删除重写成此文,随后的半个多月不断反复改进. 1. 引言 本KMP原文最初写于2年多前的201 ...

  6. poj2389-Bull Math(大整数乘法)

    一,题意: 大整数乘法模板题二,思路: 1,模拟乘法(注意"逢十进一") 2,倒序输出(注意首位0不输出) 三,步骤: 如:555 x 35 = 19425  5 5 5  5 5 ...

  7. 使用mutt+msmtp在Linux命令行界面下发邮件(续)

    一年前写过一篇<使用mutt+msmtp在Linux命令行界面下发邮件>,但是最近想照着文中的办法解决新的问题时发现又有新的疑惑了,所以就有了今天这篇“续集”. 首先说说msmtp.如果你 ...

  8. DS实验题 融合软泥怪-2 Heap实现

    题目和STL实现:DS实验题 融合软泥怪-1 用堆实现优先队列 引言和堆的介绍摘自:Priority Queue(Heaps)--优先队列(堆) 引言: 优先队列是一个至少能够提供插入(Insert) ...

  9. [转载] Ubuntu 16.04 LTS 一键安装VNC

    安装 X11VNC: sudo apt install x11vnc -y 配置访问密码: sudo x11vnc -storepasswd /etc/x11vnc.pass 创建服务: vi /li ...

  10. Microsoft Softwares

    字体   Office   运行库   框架   IE浏览器 Fonts 等线 https://www.microsoft.com/zh-cn/download/details.aspx?id=491 ...