WPF APP项目添加资源文件夹
source link: http://blog.devwiki.net/index.php/2019/12/31/add-resources-Dictionary-in-wpf-application-project.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
0x01. 概要
一般我们会在项目中某个目录中统一管理二进制资源文件, 如图片, 文档, 音频等等.
新建的WPF APP项目默认是没有类似 Android res
这样的文件夹来管理资源文件. 如何建立资源文件夹并正常使用呢?
0x02. 创建过程
1. 创建资源文件夹
对项目右键, 然后 新建 -> 文件夹
:
文件夹名称命名为自己想要名称, 比如: Resources
.
2. 创建分类文件夹
可根据需要在上一步的 Resources
文件夹内创建分类文件夹, 比如:
- Images
- Audios
3. 创建资源字典文件
在 Resources
文件右键, 新建 -> 资源字典(ResourceDictionary)文件,并填写名称.
此处填写的是 DemoRes.xaml
, 但是到这一步项目还不能识别到该文件.
4. 添加资源字典到项目配置
打开项目中的 App.xaml
文件, 在 ApplicationResource
节点中添加 ResourceDictionary
节点:
<Application x:Class="WPFDemo.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="../MainWindow.xaml"> <Application.Resources> <ResourceDictionary Source="../Resources/DemoRes.xaml"/> </Application.Resources> </Application>
这样项目就可以识别该资源字典文件了.
5. 测试识别结果
在 Resources\Images
文件夹中添加一个图片文件, 并尝试在布局文件中添加引用.
然后在布局文件中引用:
<Image x:Name="PreImage" Width="300" Height="300" Stretch="Uniform" Source="{StaticResource HeaderImage}">
然后编译测试, 可以通过~.
Recommend
-
4
WPF 给类库设置设计时使用的资源字典在开发 WPF 类库时,由于类库里面没有存在 App.xaml.cs 文件,而在对单个 XAML 进行开发时,设计器将会因为找不到资源文件的存在,而拿不到资源。本文告诉大家简单的方法,给设计器设置仅在设计时引用的资源...
-
4
批量清理 Android 项目 build 文件夹 2021-03-21 这个标题真不好取~Android 开发久了就会累积大量的垃圾文件,有些可以直接删除,有些又想保留源码,总不能每个都打开了执行 clean,这不现实。当然,自...
-
10
V2EX › Windows Win10 资源管理器里面的快速访问列表,文件夹后面的别针按钮怎么去掉啊
-
11
windows10/11 怎么让文件资源管理器里能按所有文件/文件夹混合排序,而不是文件和文件夹单独排序? V2EX › Windows windows10...
-
10
Soft 解决SynologyDriveClient添加同步文件夹无响应问题 发表于 2022.01.12 11:47 浏览量 3 没有评论...
-
7
微软 Win11 新版文件资源管理器上手体验:文件夹预览、快速访问固定、整合 OneDrive 网盘微软 Win11 新版文件资源管理器上手体验:文件夹预览、快速访问固定、整合 OneDrive 网盘2022-02-21 08:29IT之家 (玄隐)IT之家 2 月 21 日消息...
-
6
V2EX › Android 什么 APP 能扫描“.nomiedia”文件夹里面的文件?
-
6
V2EX › macOS Mac TimeMachine 无法添加群晖共享文件夹为备份磁盘
-
10
【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】 写图形界面软件的时候,我们经常会遇到一种情况。那就是图形界面上面,显示的控件可能是不定的。有可能多,也有可能少,具体显示多少内容需要根据配置文件而来。...
-
5
Jekyll 添加 public 文件夹 2024-01-06 tech jekyll 2 mins 452 字 ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK