当用户控件在另一个程序集中引用时,用户控件中引用的资源不会出现
我有 3 个程序集:
编号 1-ResourceAssembly,其中包含一个子文件夹 Images,其中包含 1 个图像(构建操作 = 资源)。该子文件夹中有一个 ResourceDictionary,其构建操作设置为资源。资源字典包含以下内容 -
<BitmapImage x:Key="BluePlus_48x48_72" UriSource="112_Plus_Blue_48x48_72.png"/>
数字 2 - 一个 wpf 控件程序集,其中包含一个名为 UserControl1 的用户控件。在该用户控件的资源中,我从程序集 1 加载资源字典并使用其中的图像。
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/ResourcesAssembly;component/Images/ImagesDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<Image Source="{DynamicResource BluePlus_48x48_72}" Height="48" Width="48"/>
图像正确显示。
第 3 号 - 主要应用程序组件。在 MainWindow.xaml 中,我引用 Project1 程序集并插入 UserControl1。
xmlns:p1="clr-namespace:Project1;assembly=Project1"
<p1:UserControl1 Height="60" Width="60"/>
但是,图像没有出现。没有编译时错误,也没有运行时输出到输出窗口的任何错误。我不知道为什么图像没有出现。有什么想法吗?
感谢您的帮助!
I have 3 assemblies:
Number 1- ResourceAssembly which contains a subfolder Images with 1 image in it (build action = resource). Within that subfolder is a ResourceDictionary with build action set to resource. The resource dictionary contains the following-
<BitmapImage x:Key="BluePlus_48x48_72" UriSource="112_Plus_Blue_48x48_72.png"/>
Number 2 - A wpf control assembly with a single usercontrol called UserControl1. Within that usercontrol's resources, I am loading the resource dictionary from assembly 1 and using the image in it.
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/ResourcesAssembly;component/Images/ImagesDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<Image Source="{DynamicResource BluePlus_48x48_72}" Height="48" Width="48"/>
The image appears correctly.
Number 3 - The main application assembly. Within the MainWindow.xaml, I reference the Project1 assembly and insert a UserControl1.
xmlns:p1="clr-namespace:Project1;assembly=Project1"
<p1:UserControl1 Height="60" Width="60"/>
However, the image does not appear. There are no compile-time errors nor any errors ouput to the Output window at runtime. I am at a loss as to why the image isn't appearring. Any thought?
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您还需要在主应用程序中添加对“ResourceAssembly”项目的引用。或者至少将“ResourceAssembly.dll”与主应用程序的可执行文件放在同一文件夹中。
I think you'll need to also add a reference to the "ResourceAssembly" project in your main application. Or at least have the "ResourceAssembly.dll" in the same folder as your main application's executable.
尝试提供如下资源参考。
注意:另外,不要忘记
Source="/
中的 /。HTH
Try giving the resource reference like below.
Note: Also, don't forgot the / in
Source="/
.HTH