locked
Merged Resource Dictionaries Causing Error in Universal App

    Question

  • I have a solution in which there are resource dictionaries in each of the projects. The projects & files involved in my problem (I think) are:

    MyApp (Windows 8.1 Project)

         ColorSelector.xaml (UserControl)

         MyAppResources.xaml (ResourceDictionary)

         MainPage.xaml (Page)

    WindowsAppExtras (PortableClassLibrary)

         SettingsResources.xaml (ResourceDictionary)

    The ColorSelector has the following in the Resources section:

    <UserControl.Resources>
    	<ResourceDictionary>
    		<ResourceDictionary.MergedDictionaries>
    			<ResourceDictionary Source="ms-appx:///WindowsAppExtras/SettingsResources.xaml"/>
    			<ResourceDictionary Source="ms-appx:///MyApp/MyAppResources.xaml"/>
    		</ResourceDictionary.MergedDictionaries>
    	</ResourceDictionary>
    </UserControl.Resources>

    And MainPage has the following:
    <Page.Resources>
    	<ResourceDictionary>
    		<ResourceDictionary.MergedDictionaries>
    			<ResourceDictionary Source="ms-appx:///MyApp/MyAppResources.xaml"/>
    			<ResourceDictionary>
    			<!--OTHER RESOURCES-->
    			</ResourceDictionary>
    		</ResourceDictionary.MergedDictionaries>
    	</ResourceDictionary>
    </Page.Resources>

    ColorSelector is, of course, used in MainPage. However, I receive the following error:

    Cycle detected in merged resource dictionaries

    I have been told that this means something about a circular reference, but I cannot figure out where that could be. Does it have something to do with the fact that I use the same ResourceDictionary in both the Page and a UserControl in that Page? The other strange thing is that there are 3 ColorSelectors next to each other (as Children in a StackPanel), but only some of them give the error, and it is not even the same ones every time (even though they have the same attributes). Can anybody tell me how to fix this error, or why it is not always the same ones that give the error? Thanks.


    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Monday, September 22, 2014 4:39 PM

Answers

  • Nathan - I don't think you should be adding resources from other projects.  The XAML needs to be distributed along with the appx, and it doesn't get included unless you specifically include it.  XAML does not get embedded in a DLL in Store apps.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, October 3, 2014 6:38 PM
    Moderator

All replies

  • Are you able to remove a resource, one at a time, until the error disappears?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, September 22, 2014 7:33 PM
    Moderator
  • OK, I found which ResourceDictionary is causing the problem. Here is that ResourceDictionary:
    <ResourceDictionary Source="ms-appx:///UniversalAppExtras/SettingsResourcesBase.xaml"
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    	<ResourceDictionary.MergedDictionaries>
    		<ResourceDictionary>
    			<Style x:Key="SettingsGridStyle" TargetType="Grid" BasedOn="{StaticResource SettingsGridBaseStyle}"/>
    			<Style x:Key="SettingsCheckBoxStyle" TargetType="CheckBox" BasedOn="{StaticResource SettingsCheckBoxBaseStyle}">
    			</Style>
    			<Style x:Key="SettingsRadioButtonStyle" TargetType="RadioButton" BasedOn="{StaticResource SettingsRadioButtonBaseStyle}">
    			</Style>
    		</ResourceDictionary>
    	</ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    As you can see from the Source attribute in the root ResourceDictionary tag, this ResourceDictionary is based on one from another project. Is this how I should be doing this, or should I be adding the following to the MergedDictionaries:
    <ResourceDictionary Source="ms-appx:///UniversalAppExtras/SettingsResourcesBase.xaml"/>

    Is one better than the other? Am I not allowed to do either one? Is there a different way I need to do it? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Monday, September 22, 2014 8:06 PM
  • Nathan - I don't think you should be adding resources from other projects.  The XAML needs to be distributed along with the appx, and it doesn't get included unless you specifically include it.  XAML does not get embedded in a DLL in Store apps.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, October 3, 2014 6:38 PM
    Moderator