Windows Phone 四、控件模版
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>
图标按钮展示内容
<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 四、控件模版的更多相关文章
- 使用代码浏览WPF控件模版
纯代码创建,不需要创建界面,创建WPF工程后,直接复制代码就可以使用. 当你手头没有Blend,又不记得以下这段代码,但是又想浏览控件模版的时候,就可以直接复制拿来用了. public partial ...
- 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog
[源码下载] 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog 作者:webabcd 介绍背水一战 Windows 10 之 控 ...
- 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu
[源码下载] 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹 ...
- 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout
[源码下载] 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout 作者:webabcd 介绍背水一战 Windows 10 之 ...
- 背水一战 Windows 10 (34) - 控件(进度类): RangeBase, Slider, ProgressBar, ProgressRing
[源码下载] 背水一战 Windows 10 (34) - 控件(进度类): RangeBase, Slider, ProgressBar, ProgressRing 作者:webabcd 介绍背水一 ...
- 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch
[源码下载] 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch 作者:webabcd 介绍背水一 ...
- 背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox
[源码下载] 背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(选择类) Sel ...
- 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButton, AppBarButton, AppBarToggleButton
[源码下载] 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButt ...
- 背水一战 Windows 10 (30) - 控件(文本类): AutoSuggestBox
[源码下载] 背水一战 Windows 10 (30) - 控件(文本类): AutoSuggestBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(文本类) AutoSug ...
随机推荐
- Ext3文件系统mount选项和文件属性介绍
mount选项 设置方式 ext3 mount选项可以通过多个方式进行设置:1)内核编译时: 内核menuconfig通过CONFIG_EXT3_DEFAULTS_TO_ORDERED编译控制选项,来 ...
- NOIP2013D1T3货车运输
题目链接:http://www.luogu.org/problem/show?pid=1967 数据:http://www.cnblogs.com/wanglichao/p/5592058.html ...
- Django分析之使用redis缓存服务器
时间长没有更新了,这段时间一直忙着一个项目,今天就记录一个现在经常会用到的技术吧. redis相信大家都很熟悉了,和memcached一样是一个高性能的key-value数据库,至于什么是缓存服务器, ...
- FLEX各种特效集合
http://www.noupe.com/adobe/flex-developers-toolbox-free-components-themes-and-tutorials.html经典中的经典 h ...
- OSG中找到特定节点的方法
OSG中找到特定节点的方法 转自:http://38288890.blog.163.com/blog/static/19612845320072721549504/ 为了在OSG中找到需要的节点并对节 ...
- css记录
padding padding-top是在绿色边框内,从顶部向下移20像素位置,默认padding-top 为0时,红色边框为20像素高,通过padding-top属性,为顶部增加了20像素,这时顶部 ...
- iOS TTF文件使用---改变字体
TTF(True Type Font):是一种字库名称 TTF文件:是Apple公司和Microsoft公司共同推出的字体文件格式 使用: 1 获取字体文件 从各种渠道下载字体ttf,网站或从别的ip ...
- vpn
https://itunes.apple.com/us/app/sonicwall-mobile-connect/id822514576?mt=12
- google protobuf初体验
最近在读别人代码的时候发现一个的东西,名字叫protobuf, 感觉挺好用的,写在这里,留个记录.那么什么是protobuf 呢?假如您在网上搜索,应该会得到类似这样的文字介绍: Google Pro ...
- 腾讯QQ认证空间4月27日已全面开放申请,欲进军自媒体
今天看到卢松松的博客上爆出,腾讯QQ认证空间4月27日已全面开放申请的消息,这一消息出来, 马浩周根据提示方法进行申请,下面先说说腾讯QQ认证空间的申请方法: QQ认证空间开放申请公告地址:http: ...