WPF资源字典

如果相同的资源可用于不同的应用程序,把资源放在一个资源字典中就比较有效。

新建一个资源字典文件Dictionary1.xaml

 1 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 2                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 3     
 4     
 5     <!--线性渐变画笔-->
 6     <LinearGradientBrush x:Key="CyanGradientBrush" StartPoint="0,0" EndPoint="0.3,1">
 7         <GradientStop Offset="0.0" Color="LightCyan"/>
 8         <GradientStop Offset="0.14" Color="Cyan"/>
 9         <GradientStop Offset="0.7" Color="DarkCyan"/>
10     </LinearGradientBrush>
11     
12     <Style x:Key="PinkButtonStyle" TargetType="Button">
13         <Setter Property="FontSize" Value="22"/>
14         <Setter Property="Foreground" Value="White"/>
15         <Setter Property="Background">
16             <Setter.Value>
17                 <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
18                     <GradientStop Offset="0.0" Color="Pink"/>
19                     <GradientStop Offset="0.3" Color="DeepPink"/>
20                     <GradientStop Offset="0.9" Color="DarkOrchid"/>
21                 </LinearGradientBrush>
22             </Setter.Value>
23         </Setter>
24     </Style>
25     <!--对于目标项目,需要引用这个库,并把资源字典添加到这个字典中。-->
26     <!--通过ResourceDictioinary的MergeDicitonaries属性,可以使用添进来的多个资源字典文件-->
27 </ResourceDictionary>

 


 对于目标项目,需要引用这个库,并把资源字典添加到这个字典中。通过ResourceDictionary的MergedDictionaries属性,可以使用添加进来 的多个资源字典文件。

 1 App.xaml
 2 
 3 <Application x:Class="WPF_Test.App"
 4              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 5              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 6              StartupUri="Resources_Test.xaml">
 7     <Application.Resources>
 8         <ResourceDictionary>
 9             <ResourceDictionary.MergedDictionaries>
10                 <ResourceDictionary Source="Dictionary1.xaml"/>
11             </ResourceDictionary.MergedDictionaries>
12         </ResourceDictionary>
13     </Application.Resources>
14 </Application>

 

  现在就可以像使用本地资源那样使用引用程序集中的资源了:

1 <Button Name="PinkButton" Width="300" Height="50" Style="{StaticResource PinkButtonStyle}" Content="Referenced Resource"/>

 

转载于:https://www.cnblogs.com/zhaotianff/p/5521364.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值