0

I want to merge one XAML file, that only contains styles into the Window.Resource of my application. I tried using MergedDictionaries as described in WPF Reference custom resource defined in another xaml file .

First: The File is named "MyStyleDocument.xaml" and contains different WPFstyles without using x-Keys.

 <ResourceDictionary 
   xmlns=" http://schemas.microsoft.com/winfx/2006/xaml/presentation "
   xmlns:x=" http://schemas.microsoft.com/winfx/2006/xaml ">

  <Style  TargetType="{x:Type TabControl}">
   (...)
  </Style>
  <Style  TargetType="{x:Type XY}">
   (...)
  </Style>
    .
    .
    .
</ResourceDictionary>

Second:

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries> 
            <ResourceDictionary Source="MyStyleDocument.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

I get the Result: "An error occurred while finding the resource dictionary "MyStyleDocument.xaml"." The file is located in the folder of my project.

My question is: How can I cleverly include one XAML file containing different styles into another XAML code?

The structure of my project is: WPFApplication(file folder1) -> File Folder1 includes WPFApplication(file folder2);WPFApplication.sln; WPFApplication.suo; WPFApplication.v11.suo File Folder 2 includes: bin (file folder2.1); obj(file folder2.2); Properties(filefolder2.3); App.xaml; App.xaml.cs; Application.ico; MainWindow.xaml.cs; MyStyleDocument.xaml; WpfApplication.csproj

Community
  • 1
  • 1
Malvina
  • 3
  • 5
  • 1
    To answer your question, we need to know the sctructure of your project. Could you please add structure of your projects including folders where MyStyleDocument.xaml and your Window are located – keymusicman Aug 20 '15 at 20:00
  • Check [this](http://stackoverflow.com/questions/338056/resourcedictionary-in-a-separate-assembly) question – keymusicman Aug 20 '15 at 20:31
  • Thanks for your respond. I added the structure of the project and I´ll check the suggested question. – Malvina Aug 21 '15 at 10:47

1 Answers1

0

Here is a demo wpf project:

-WpfApplication
 |--App.xaml
 |--MyStyle[here is a floder]
   |---MyStyleDocument1.xaml
   |---MyStyleDocument2.xaml
   |---MyStyleDocument3.xaml

Then you can edit App.xaml like this:

 <Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
              <!--add style file here like this-->
              <ResourceDictionary Source="/MyStyle/MyStyleDocument1.xaml" />
        </ResourceDictionary.MergedDictionaries>
    <ResourceDictionary>
 <Application.Resources>
chengzi
  • 170
  • 2
  • 10