Welcome

首页 / 软件开发 / .NET编程技术 / Windows 8 Store Apps学习(15) 控件 UI: 字体继承

Windows 8 Store Apps学习(15) 控件 UI: 字体继承2013-12-04 cnblogs webabcd控件 UI: 字体继承, Style, ControlTemplate, SystemReso

介绍

重新想象 Windows 8 Store Apps 之 控件 UI

字体继承 - 继承父辈的 Font 相关的信息

Style - 样式

ControlTemplate - 控件模板

系统资源 - 系统内置的样式资源

VisualState - 视 图状态

VisualStateManager - 视图状态管理器

示例

1、演示字体继承

Controls/UI/FontInherit.xaml

<Pagex:Class="XamlDemo.Controls.UI.FontInherit"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="using:XamlDemo.Controls.UI"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d"FontSize="100"><Grid Background="Transparent"><StackPanel Margin="120 0 0 0"><!--演示如何继承父辈的 Font 相关的信息Font 相关的设置来自 Windows.UI.Xaml.Controls.Control--><!--继承了 Page 的关于 Font 的设置--><TextBlock Text="FontSize = 100" /><UserControl FontSize="50"><!--继承了 UserControl 的关于 Font 的设置--><TextBlock Text="FontSize = 50" /></UserControl></StackPanel></Grid></Page>
2、演示 Style

Controls/UI/Style.xaml

<Pagex:Class="XamlDemo.Controls.UI.Style"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="using:XamlDemo.Controls.UI"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d"><Grid Name="root" Background="Transparent"><!--注:、在 Grid.Resources 指定的资源,其作用域仅在 Grid 之内,全局资源需要在 App.xaml 中配置、Grid.Resources 等非全局资源也是支持 ResourceDictionary 的--><Grid.Resources><!--Style - 样式x:Key - 标识(不指定此值,则样式会应用于所有 TargetType 所指定的类型)TargetType - 目标对象类型BasedOn - 指定当前样式的父样式(此样式会继承指定的父样式)Setter - 属性设置器Property - 需要设置的属性名称Value - 需要设置的属性值--><Style x:Key="MyTextStyle" TargetType="TextBox"><Setter Property="FontSize" Value="24"/><Setter Property="Foreground" Value="#0000FF"/></Style><Style x:Key="MyTextStyle2" TargetType="TextBox"><Setter Property="FontSize" Value="24"/><Setter Property="Foreground" Value="#FF0000"/></Style><Style TargetType="TextBox" BasedOn="{StaticResource MyTextStyle}"><Setter Property="TextAlignment" Value="Center"/></Style></Grid.Resources><StackPanel Margin="120 0 0 0"><!--通过指定样式资源,修改 FrameworkElement 的样式(Style 属性来自 FrameworkElement)--><TextBox Name="txtStyleDemo" Text="我是 TextBox" Margin="5" Style="{StaticResource MyTextStyle}" /><!--隐式样式(即全局样式,即样式资源中未指定 key 的样式)的应用--><TextBox Text="我是 TextBox" Margin="5" /><!--动态改变 FrameworkElement 的样式--><Button Name="btnChangeStyle" Content="改变样式" Click="btnChangeStyle_Click_1" /></StackPanel></Grid></Page>