如何在类库中加载资源 [英] How to Load Resource in a class library
问题描述
我想在类库中实现一些包含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屋!