【Windows Phone 8】样式
类似于Html样式,有三种设置方法。
1.内联样式
直接在控件中设置样式,类似于html中的控件中设置样式。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <Button Content="内联样式"> 2 <Button.Style> 3 <Style TargetType="Button"> 4 <Setter Property="Background" Value="Red"></Setter> 5 <Setter Property="FontSize" Value="20"></Setter> 6 </Style> 7 </Button.Style> 8 </Button>
2.内部样式表
在xaml页面定义的样式,通过x:key设置样式名称
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <phone:PhoneApplicationPage.Resources> 2 <Style x:Key="CommonButton" TargetType="Button"> 3 <Setter Property="Background" Value="Blue"></Setter> 4 <Setter Property="FontSize" Value="25"></Setter> 5 </Style> 6 </phone:PhoneApplicationPage.Resources>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <Button Content="导航到Page1" Style="{StaticResource CommonButton}" />
3.外部样式
类似于html的css样式文件,将样式集中定义在外部的样式文件中。
关于xaml样式文件的定义可以参考Windows Phone SDK安装后文件中的ThemeResources.xaml文件,在此基础上进行修改。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <ResourceDictionary 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:System="clr-namespace:System;assembly=mscorlib"> 5 6 <Style x:Name="ButtonOutStyle" TargetType="Button"> 7 <Setter Property="Background" Value="Green"></Setter> 8 <Setter Property="FontSize" Value="30"></Setter> 9 </Style> 10 </ResourceDictionary> 11 12
同时需要修改App.xaml文件,添加该样式资源
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <Application.Resources> 2 <ResourceDictionary> 3 <ResourceDictionary.MergedDictionaries> 4 <ResourceDictionary Source="CustomTheme/ThemeResources.xaml"/> 5 </ResourceDictionary.MergedDictionaries> 6 </ResourceDictionary> 7 </Application.Resources>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <Button Content="外部样式" Style="{StaticResource ButtonOutStyle}"></Button>
请注明文章出处[http://www.cnblogs.com/fb-boy/]