Reputation: 3
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
Upvotes: 0
Views: 560
Reputation: 180
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>
Upvotes: 0