开发者

Resource referenced in user control does not appear when user control is referenced in another assembly

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!


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.


Try giving the resource reference like below.

<ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/YourAssembly.Name;component/Images/ImagesDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

<Image Source="{StaticResource BluePlus_48x48_72}" Height="48" Width="48"/>

Note: Also, don't forgot the / in Source="/ .

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜