How to create a Merged "ResourceDictionaries"

2

I have a small example where I created an application-level resource:

<Application x:Class="teste1.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:teste1"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <SolidColorBrush x:Key="texto" Color="Yellow"/>
    <SolidColorBrush x:Key="texto1" Color="#FF5E1AC1"/>
    <Color x:Key="fundo1">#FFBF3B3B</Color>
</Application.Resources>

What should I do in order to change this Resource to a separate file so that all settings in terms of style are exclusively in that file? I tried some searches related to "Merged ResourceDictionaries" but without success.

I just did it. Will it make sense?

<Application x:Class="teste1.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:teste1"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <!--<ResourceDictionary.MergedDictionaries>-->
        <ResourceDictionary Source="MeuResourceDictionary/MeuResourceDictionary.xaml"/>
    <!--</ResourceDictionary.MergedDictionaries>-->
</Application.Resources>

    
asked by anonymous 02.04.2016 / 12:24

1 answer

3

Create a xaml file with the ResourceDictionary declaration:

<ResourceDictionary
    <SolidColorBrush x:Key="texto" Color="Yellow"/>
    <SolidColorBrush x:Key="texto1" Color="#FF5E1AC1"/>
    <Color x:Key="fundo1">#FFBF3B3B</Color>
</ResourceDictionary>

Give it whatever name you want, eg MeuResourceDictionary.xaml
Use it this way:

<Application x:Class="teste1.App"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:local="clr-namespace:teste1"
     StartupUri="MainWindow.xaml">

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="caminhoAte\MeuResourceDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
....
....
</Application>
    
02.04.2016 / 13:08