Page 1 of 1

[SOLVED] Reference external ResourceDictionary

Posted: Tue Aug 28, 2018 7:49 am
by TooTallTommyT
I have a ResourceDictionary that I've moved to an external assembly, so that I can use it across all my apps, but I cannot seem to find the right approach to make it visible/usable in my projects. I've tried a variety of methods of setting Source attribute to no avail. Any suggestions?

Re: Reference external ResourceDictionary

Posted: Wed Aug 29, 2018 2:50 am
by JS-Support @Userware
Hi,

You need to add a reference to it using the "MergedDictionaries" syntax. For example, you can reference it in the "App.xaml" file of your startup project so that it becomes visible application-wide. To do so, please use the following example:

Code: Select all

<Application
    x:Class="MyApplication1.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="MyResourceDictionary1.xaml"/>
                <ResourceDictionary Source="Themes/Generic.xaml"/>
                <ResourceDictionary Source="ASSEMBLYNAME;component/FOLDERNAME/FILENAME.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>


(you need to replace "ASSEMBLYNAME", "FOLDERNAME", and "FILENAME" with the actual values)

Regards,
JS-Support

Re: Reference external ResourceDictionary

Posted: Wed Aug 29, 2018 11:29 am
by TooTallTommyT
That mostly did the trick.... I did have to add forward slash ( / ) preceding the assemblyname, but once done, it worked perfectly!
Thanks!

<ResourceDictionary Source=ASSEMBLYNAME;component/FOLDERNAME/FILENAME.xaml/>

to:

<ResourceDictionary Source=/ASSEMBLYNAME;component/FOLDERNAME/FILENAME.xaml/>

Re: Reference external ResourceDictionary

Posted: Thu Aug 30, 2018 6:41 am
by TaterJuice
TooTallTommyT wrote:That mostly did the trick.... I did have to add forward slash ( / ) preceding the assemblyname, but once done, it worked perfectly!
Thanks!

<ResourceDictionary Source=ASSEMBLYNAME;component/FOLDERNAME/FILENAME.xaml/>

to:

<ResourceDictionary Source=/ASSEMBLYNAME;component/FOLDERNAME/FILENAME.xaml/>


Thanks for sharing your solution with the community, Tommy!