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"/>
  • 相关阅读:
    洛谷 P1981 表达式求值
    1696:逆波兰表达式
    C# winform选择文件、选择文件夹、打开文件
    建立二叉树的二叉链表存储结构(严6.70)
    二叉树的深度
    Sequence
    c++优先队列(priority_queue)用法详解
    二叉树的操作
    [清华集训2015]灯泡(浙江大学ZOJ 3203 Light Bulb)
    Go 和 Colly笔记
  • 原文地址:https://www.cnblogs.com/zhaotianff/p/5521364.html
Copyright © 2011-2022 走看看