首页 > 其他分享 >WPF Add ResourceDictionary file and declared in app.xaml

WPF Add ResourceDictionary file and declared in app.xaml

时间:2024-03-24 21:13:42浏览次数:166  
标签:declared App Add file ResourceDictionary xaml

//Add resource dictionary file  named Brushes.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <LinearGradientBrush EndPoint="1,0" x:Key="brush1">
        <GradientStop Color="Yellow" Offset="0"/>
        <GradientStop Color="Orange" Offset="0.7"/>
        <GradientStop Color="DarkRed" Offset="1"/>
    </LinearGradientBrush>
</ResourceDictionary>



//Declared in the App.xaml  via ResourceDictionary.MergedDictionary so that it can available for the whole project

//App.xaml
<Application x:Class="WpfApp15.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:WpfApp15"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Resources/Brushes.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>


//Main.xaml

<Window x:Class="WpfApp15.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp15"
        mc:Ignorable="d" WindowState="Maximized"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Ellipse Fill="{StaticResource brush1}"/>
    </Grid>
</Window>

 

 

 

The key located at declaration the newly added resource dictionary file via ResourceDctionary.MergedDictionary so it will be accessed in the project

//App.xaml
<Application x:Class="WpfApp15.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:WpfApp15"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Resources/Brushes.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

 

标签:declared,App,Add,file,ResourceDictionary,xaml
From: https://www.cnblogs.com/Fred1987/p/18093053

相关文章

  • PhpStrom启动报错, java.net.BindException: Address already in use: bind
    问题描述:今天启动phpstromIDE时,突然报错,报错信息如下图:问题分析1.不正确关闭应用(强制关闭):可能是之前启动了一个本地web服务占了端口,在没有停掉服务,直接关闭IDE导致的(尝试了重启电脑也没解决)2.其他应用占用端口:安装了Hyper-V导致端口被占用?显然我的是第一种情况问题解决......
  • wpf add resource dynamically in cs file
    //xaml<Windowx:Class="WpfApp12.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mic......
  • add shortcut
    @echooff%1%2ver|find"5.">nul&&goto:Adminmshtavbscript:createobject("shell.application").shellexecute("%~s0","goto:Admin","","runas",1)(window.close)&goto:eof:Adminsetcurr......
  • Oracle函数7—日期函数(sysdate 、to_date、add_months、last_day......)
    文章目录1、日期获取(sysdate、current_date)2、设置时间格式(to_date、to_char)3、两个日期的差(直接加减)4、月份加减(add_months)5、取某月最后一天(last_day)6、两个日期相差月份数(months_between)7、获取下个周几是几号(next_day)8、获取指定时间的年或月或日(extract)9、时间的四......
  • 【飞浆AI实战】交通灯检测:手把手带你入门PaddleDetection,从训练到部署
    前言本次分享将带领大家从0到1完成一个目标检测任务的模型训练评估和推理部署全流程,项目将采用以PaddleDetection为核心的飞浆深度学习框架进行开发,并总结开发过程中踩过的一些坑,希望能为有类似项目需求的同学提供一点帮助。项目背景和目标背景:目标检测是计算机视觉的一......
  • linux下InetAddress.getLocalHost()很慢10s
    问题原因:执行InetAddress.getLocalHost()方法的时候,根据系统名称去hosts文件里找匹配的ip发现找不到合适的IP,一直处于等待状态。解决办法:1、查看本机系统名称 2、编辑hosts文件,在其后补充“cenos1”     参考链接:https://blog.csdn.net/lijun169/article/detail......
  • 内存检测工具——ASan(AddressSanitizer)的介绍和使用
    ASan介绍ASan全称AddressSanitizer,是一种内存错误检测工具,目的是帮助开发者检测和调试内存相关的问题,如使用未分配的内存、使用已释放的内存、堆内存溢出等。ASan是由Google开发的,广泛用于C、C++等语言的代码中。ASan的工作原理是在编译时将额外的代码插入到目标程序中,对内存的......
  • 使用 openssl 进行 RSA/ECB/PKCS1PADDING 加解密
    使用java进行RSA/ECB/PKCS1PADDING是非常方便的,例如下面的示例publicstaticStringpublicDecrypt(PublicKeypublicKey,Stringencrypted)throwsException{Ciphercipher=Cipher.getInstance("RSA/ECB/PKCS1Padding");cipher.init(Cipher.DECRYPT_......
  • [983] Add a notification after finishing the Python script
    ref:HowtoimplementaPythondesktopnotifierusingtheplyermoduleYoucangenerateanotificationafteryourPythoncodefinishesexecutingusingvariousmethods.Hereareafewoptions:UsingPlyer(Cross-Platform):Installthe plyer libraryusi......
  • GIS人必备神器降临!快速搞定洪水淹没分析!ArcGIS AddIn无源淹没分析插件!
            最近有很多小伙伴给我发私信,想使用我开发的一款基于无源淹没分析算法对洪水淹没进行分析的GIS插件。大部分小伙伴是因为看了我之前发的一个讲解洪水淹没分析算法的视频,在视频中我给大家展示了给某高校水利课题组开发的两款用于洪水淹没分析的插件:一个是基于8邻......