【Windows Phone 8】樣式

相似於Html樣式,有三種設置方法。css

1.內聯樣式html

直接在控件中設置樣式,相似於html中的控件中設置樣式。ide

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.內部樣式表spa

在xaml頁面定義的樣式,經過x:key設置樣式名稱code

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>
內部樣式表--定義樣式
1 <Button Content="導航到Page1" Style="{StaticResource CommonButton}" />
內部樣式表--使用樣式

3.外部樣式xml

相似於html的css樣式文件,將樣式集中定義在外部的樣式文件中。htm

關於xaml樣式文件的定義能夠參考Windows Phone SDK安裝後文件中的ThemeResources.xaml文件,在此基礎上進行修改。blog

 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文件,添加該樣式資源資源

1 <Application.Resources>       
2   <ResourceDictionary>           
3   <ResourceDictionary.MergedDictionaries>               
4     <ResourceDictionary Source="CustomTheme/ThemeResources.xaml"/>
5   </ResourceDictionary.MergedDictionaries>       
6   </ResourceDictionary>   
7 </Application.Resources> 
App.xaml
1 <Button Content="外部樣式" Style="{StaticResource ButtonOutStyle}"></Button>
外部樣式--使用樣式
相關文章
相關標籤/搜索