Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import multiple resource files in app.xaml wpf

Tags:

wpf

[Running on Windows 8] I know how to import a single one, like this:

<Application.Resources>
        <ResourceDictionary Source="Styles\MyCombobox.xaml"/>       
 </Application.Resources> 

but I want something like this:

<Application.Resources>
        <ResourceDictionary Source="Styles\X.xaml"/>       
        <ResourceDictionary Source="Styles\Y.xaml"/>       
        <ResourceDictionary Source="Styles\Z.xaml"/>       
 </Application.Resources> 

I get:

The property Resource can only be set once!

enter image description here

like image 950
Legends Avatar asked Aug 14 '16 22:08

Legends


1 Answers

You should merge that dictionaries.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Styles\X.xaml"/>       
            <ResourceDictionary Source="Styles\Y.xaml"/>       
            <ResourceDictionary Source="Styles\Z.xaml"/>       
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

More in documentation

UPDATE

Of course, you should wrap property usage in ResourceDictionary tag.

like image 151
Hamlet Hakobyan Avatar answered Oct 31 '22 01:10

Hamlet Hakobyan