How to create a Merged "Resourcedictionaries"

Asked

Viewed 31 times

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 to change this "Resource" to a separate file so that all style settings stay exclusively in that file?
I tried some research related to "Merged Resourcedictionaries" but without success.

That’s all I got. It’ll 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>

1 answer

3


Create a file shaman with the declaration of Resourcedictionary:

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

Name it whatever you want, ex.: 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.