0

For my application themes, I created a separate class library MyApp.Themes.dll. In the root folder of this library I have Standard.xaml:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary 
      Source="pack://application:,,,/MyApp.Themes;component/Standard/Accordion.xaml"/>
  </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

In Standard folder I have Accordion.xaml:

<ResourceDictionary xmlns:layoutPrimitivesToolkit="..."
                    xmlns:layoutToolkit="..."
                    ...>
  <!--  layoutPrimitivesToolkit:AccordionButton  -->
  <Style TargetType="layoutPrimitivesToolkit:AccordionButton">
    ...
  </Style>

  ...
</ResourceDictionary>

which are default styles for WPF Toolkit Accordion control, except that style for AccordionItem is modified to set background to transparent (instead of blue, which is a known bug).

For both xaml files Build Action is set to "Resource". Now, after referencing MyApp.Themes library in MyApp WPF project, in App.xaml I wrote the following:

<Application.Resources>
  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary             
        Source="pack://application:,,,/MyApp.Themes;component/Standard.xaml" />
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
</Application.Resources>

It doesn't work (no error; just style not applied). If I copy&paste Accordion.xaml styles directly in App.xaml, then it works. Some people suggested adding dummy resource dictionary, so I added the following in App.xaml after MergedDictionaries ending tag:

<Style TargetType="{x:Type layoutToolkit:AccordionItem}" /> 

Again, it doesn't work. Can someone help me solve this? By the way, I didn't try an approach suggested by some others - using basedOn. If I must do that, I'd like to do in MyApp.Themes, because it makes using themes nicer in App.xaml. Thank you in advance.

UPDATE1: It works if I directly copy&paste Accordion.xaml content to Standard.xaml

UPDATE2: I tried local assembly resource file URI (http://msdn.microsoft.com/en-us/library/aa970069.aspx) in Standard.xaml:

<ResourceDictionary Source="pack://application:,,,/Standard/Accordion.xaml"/>

It throws an error, saying standard/accordion.xaml not found.

synergetic
  • 7,756
  • 8
  • 65
  • 106

1 Answers1

1

It seems there's a bug in .NET. See the thread below:

Trouble referencing a Resource Dictionary that contains a Merged Dictionary

Also, there's a connect page on Microsoft site:

https://connect.microsoft.com/VisualStudio/feedback/details/609601/merge-dictionaries-does-not-work-when-we-merge-merged-dictionaries#tabs

Community
  • 1
  • 1
synergetic
  • 7,756
  • 8
  • 65
  • 106