Question

I've got a Silverlight 5 application that just refuses to accept anything in its Application.Resources tags:

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
         x:Class="My.Awesome.App"
         >
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Assets/Styles.xaml"/>
            <ResourceDictionary>
                <App:ApplicationResources x:Key="ApplicationResources" />
            </ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

Neither the Styles.xaml nor the ApplicationResources are available to my controls. For example:

<controls:ChildWindow
x:Class="My.Awesome.ErrorWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Title="{Binding Path=Errors.ErrorWindowTitle, Source={StaticResource ApplicationResources}}"
Style="{StaticResource ErrorWindowStyle}">

That control will throw its bananas at runtime, but works fine in the Visual Studio editor (I can see the text coming from my ApplicationResources). The App:ApplicationResources from the App.xaml is as follow:

namespace My.Awesome
{
    using System;
    using System.ComponentModel;
    using System.Globalization;
    using System.Windows.Browser;

    /// <summary>
    /// Wraps access to the strongly-typed resource classes so that you can bind control properties to resource strings in XAML.
    /// </summary>
    public sealed class ApplicationResources
    {
        private static readonly ApplicationStrings applicationStrings = new ApplicationStrings();
        private static readonly ErrorResources errorResources = new ErrorResources();

        /// <summary>
        /// Gets the <see cref="ApplicationStrings"/>.
        /// </summary>
        public ApplicationStrings Strings
        {
            get { return applicationStrings; }
        }

        /// <summary>
        /// Gets the <see cref="ErrorResources"/>.
        /// </summary>
        public ErrorResources Errors
        {
            get { return errorResources; }
        }
    }
}

And I have the corresponding ApplicationStrings.resx and ErrorResources.resx with the correct namespace specified (My.Awesome) and with the PublicResXFileCodeGenerator processor.

I narrowed it down to the Application.Resources dictionary not working because if I do this in the code behind:

this.Resources.Add("ApplicationResources", new ApplicationResources());

and remove the reference to Styles, then the application runs.

For reference I extracted the ErrorWindow.xaml, Styles.xaml and both .resx from a Silverlight Business Application template; it worked fine there I just can't figure out why it does not work in this app.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top