标签:
1、内联样式
<TextBlock FontSize="20" Foreground="Blue">好啊</TextBlock>
2、页面样式
<Button Height="20" Margin="0,78,445,213>按钮1</Button>
<Button Width="50" Height="20" Margin="0,116,453,175">按钮2</Button>
<Window.Resources>
<Style TargetType="Button" x:Key="MyStyle">
<Setter Property="Foreground" Value="Blue"></Setter>
<Setter Property="FontSize" Value="30"></Setter>
</Style>
</Window.Resources>
应用特性名称样式:
在样式中添加x:key属性
<Style TargetType="Button" x:Key="MyStyle">
<Setter Property="Foreground" Value="BlanchedAlmond"></Setter>
<Setter Property="FontSize" Value="30"></Setter>
</Style>
然后应用该样式 <Button Height="20" Margin="0,78,445,213" Style="{StaticResource MyStyle}">按钮1</Button>
3、全局样式
在App.xaml中添加
<Application.Resources>
<Style TargetType="Button" x:Key="MyStyle">
<Setter Property="Foreground" Value="Blue"></Setter>
<Setter Property="FontSize" Value="30"></Setter>
</Style>
</Application.Resources>
4、外部样式
新建Dictionary1.xaml文件
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="Button" x:Key="MyStyle">
<Setter Property="Foreground" Value="Blue"></Setter>
<Setter Property="FontSize" Value="30"></Setter>
</Style>
</ResourceDictionary>
在引用页面添加
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
标签:
原文地址:http://www.cnblogs.com/Benjamin/p/3870620.html