Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 265531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:46:42+00:00 2026-05-11T22:46:42+00:00

I have custom classes that I currently instantiate within App.xaml as resources. I want

  • 0

I have custom classes that I currently instantiate within App.xaml as resources. I want to move these custom objects into a Merged ResourceDictionary, where they are used within styles, and keep them close to where they are used.
Here’s an example of what I want, arbitrarily using fake converter objects, but they could be any custom object…

App.xaml (namespace declarations ommitted):

<Application.Resources>
<ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Merged.xaml" />
    </ResourceDictionary.MergedDictionaries>
    <Style x:Key="SomeStyle" TargetType="SomeControl">
        ...
    </Style>
    ...

</ResourceDictionary>

And then in Merged.xaml (namespace declarations omitted):

<ResourceDictionary>
    <cvt:VisibilityToBoolConverter x:Key="BoolToVisibility" Inverted="True"/>
    <cvt:VisibilityToBoolConverter x:Key="NotBoolToVisibility" Inverted="True" Not="True"/>

    <Style x:Key="SomethingThatUsesVisibilityToBoolConvertersStyle" TargetType="SomeOtherControl">
        ....
    </Style>
</ResourceDictionary>

The issue I’m seeing is this: when I create the BoolToVisibility and NotBoolToVisibility objects (as well instantiating other objects that are instances of custom classes I have created) just as part Application.Resources, they are created and all the references work as expected; however, when I move these into a Merged Resource Dictionary (as I have in the sample above), I get a malformed Application exception when the Silverlight application loads.

I belive this to be an issue with how objects are instantiated differently in Merged Resource Dictionaries (I belive it is more of a lazy-load approach), but I would expect it to work nonetheless.

I am very much able to add Style objects, DataTemplates, ControlTemplates, and the like. But when I want to create instances of custom classes that are named or keyed using Xaml, it works great inside of App.xaml’s Application.Resources directly and Application.Resources/ResourceDictionary as well. As soon as they are moved into a merged dictionary, it throws the exception. Is this by design? Any other ideas that work? Thanks in advance…

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:46:42+00:00Added an answer on May 11, 2026 at 10:46 pm

    I have FINALLY worked around this. I took a page out of how the App class gets instantiated and did the same with the Merged.xaml file. I created a class with “code-behind” for Merged.xaml, called Merged that inherits from ResourceDictionary. I then (borrowing from App.g.cs), I initialize the component by loading from the Merged.xaml file during construction.

    Merged.xaml.cs:

    public partial class Merged : ResourceDictionary
    {
        private bool _contentLoaded;
    
        public Merged()
        {
            InitializeComponent();
        }
    
        public void InitializeComponent() 
        {
            if (_contentLoaded) 
            {
                return;
            }
            _contentLoaded = true;
            System.Windows.Application.LoadComponent(this, new System.Uri("/MySilverlightApp;component/Merged.xaml", System.UriKind.Relative));
        }
    }
    

    The Merged.xaml file looks exactly the same as in my original question, using ResourceDictionary as it’s root element.
    The App.xaml is SLIGHTLY different. Instead of referencing the Merged ResourceDictionary by using the ResourceDictionary element and the Source attribute, I simply referenced the Merged class:

    <Application.Resources
    xmlns:msa="clr-namespace:MySilverlightApplication">
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <msa:Merged />
        </ResourceDictionary.MergedDictionaries>
        <Style x:Key="SomeStyle" TargetType="SomeControl">
            ...
        </Style>
        ...
    </ResourceDictionary>
    </Application.Resources>
    

    Viola! It works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have authored some custom classes that I would like to create using XAML:
I currently have a simple iPhone app that loads a custom subclass of UIView.
Aloha, I have a custom control that I need to instantiate from within a
I currently have div classes for filters that cannot be changed. I want to
I'm currently implementing a custom MultiPageEditorPart where I want to have multiple pages when
I have a certain class structure in my app, that currently utilizes django for
I have a custom class that is currently not extending anything (it's for executing
I have a set of .net classes that I currently serialize and use with
I'm currently developing an app that has a camera functionality, with a custom camera
I have a custom ViewEngine that I am using with my MVC4 web app.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.