How to import a deep hierarchy of merged dictionaries with 1 ResourceDictionary?

I am trying to combine dictionaries from a project of a library of dependent classes, but resource keys cannot be found. Note. I use this workaround to connect to Microsoft from Microsoft , which should allow the structure to search deep enough to find the embedded resources. This does not work.

Failure example

<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/MyApplication.ControlLibrary;component/ResourceDictionaries/ResourceLibrary.xaml" /> <ResourceDictionary> <Style TargetType="{x:Type Line}" /> <!-- workaround from MS to allow for this --> <Main:AppBootstrapper x:Key="bootstrapper" /> <!-- CaliburnMicro bootstrapper, unsure if this is relevant --> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> 

Inside ResourceLibrary.xaml

 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="DefaultColorTheme.xaml" /> <!-- ...snip... --> <ResourceDictionary Source="TransitionControl.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> 

However, he cannot find the resource keys. If I combine each dictionary manually from this class library, it works fine. This, IMO, is beginning to defeat the goal of abstracting resources to an external assembly.

Success example

 <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/MyApplication.ControlLibrary;component/ResourceDictionaries/DefaultColorTheme.xaml" /> <ResourceDictionary Source="/MyApplication.ControlLibrary;component/ResourceDictionaries/Images.xaml" /> <ResourceDictionary Source="/MyApplication.ControlLibrary;component/ResourceDictionaries/FontIcons.xaml" /> <ResourceDictionary> <Style TargetType="{x:Type Line}" /> <Main:AppBootstrapper x:Key="bootstrapper" /> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> 

Did I put dummy implicit style in the wrong place? Something here does not add up. Thanks for watching.

+3
source share
1 answer

I learned this hard way by playing with him for 3 days.

Do not create really deep structures. You have a main dictionary that just uses other dictionaries. The application should not receive anything from others.

But the most important thing is to contact them in the correct order. it will not work if you load RD where one of its contents uses something from another that has not yet been loaded. The order is really important.

Using WPF Inspector will help you a lot, as it allows you to keep track of anything in a WPF application.

0
source

Source: https://habr.com/ru/post/1259726/


All Articles