如何在类库中加载资源 [英] How to Load Resource in a class library

查看:77
本文介绍了如何在类库中加载资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


   我想在类库中实现一些包含png图像的自定义控件。和其他人可以在他们的UWP项目中轻松添加引用和使用自定义控件。但我无法正确引用这些图像资源。


所以我的问题是,在我的自定义控件中使用这些资源的正确方法是什么,谢谢



构建操作:嵌入式资源


不复制


< ImageBrush x:Key =" MyBackgroundImg" ;的ImageSource = QUOT; / MyCustomControlDll; Compontent /资产/ bg.png" />
$
< BitmapImage x:Key =" MyBitmapImg" UriSource = QUOT; / MyCustomControlDll; Compontent /资产/ bg.png" />

解决方案


如果您将"构建操作"设置为"内容"并将"复制到输出目录"设置为"始终",则该文件随您的软件包一起分发,您可以使用ms-appx表示法(带有三个斜杠) )引用其位置:

< ImageBrush x:Key =" MyBackgroundImg"的ImageSource = QUOT; MS-APPX:///MyCustomControlDll/Asset/bg.png" /> 

以下是
UWP评级控制
也是如此。




hi,

   I would like to implement a custom control with some png images in a class library. and other people can add reference and use the custom control easily in their UWP project. But I can not reference these image resource correctly.

so my question is, what is the right way to use these resources in my custom control, thanks

build action : embedded resource

do not copy

<ImageBrush x:Key="MyBackgroundImg" ImageSource="/MyCustomControlDll;Compontent/Asset/bg.png" />
<BitmapImage x:Key="MyBitmapImg" UriSource="/MyCustomControlDll;Compontent/Asset/bg.png" />

解决方案

Hi,

if you set the 'build action' to 'content' and 'copy to output directory' to 'always', then the file is distributed with your package and you can use the ms-appx notation (with three slashes) to refer to its location :

<ImageBrush x:Key="MyBackgroundImg" ImageSource="ms-appx:///MyCustomControlDll/Asset/bg.png" />

Here's an example of a UWP rating control that does the same.


这篇关于如何在类库中加载资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆