zoukankan      html  css  js  c++  java
  • 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"/>
  • 相关阅读:
    缓存雪崩与缓存穿透
    读取表中最大值
    使用vscode在谷歌上运行代码
    elment 中tree组件展开所有和收缩所有节点
    深度系统商店提示无法安装软件依赖错误
    诗词,理解,品论
    《45个十分钟读懂资本论》原文、适合朗读版和个人见解
    《论持久战》全文
    OSError: [WinError 126] 找不到指定的模块。
    C++ 获取序列最大(或最小)的 N 个元素
  • 原文地址:https://www.cnblogs.com/zhaotianff/p/5521364.html
Copyright © 2011-2022 走看看