WPF 四种样式

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>

 

转载于:https://www.cnblogs.com/Benjamin/p/3870620.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值