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 3426978
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:46:51+00:00 2026-05-18T06:46:51+00:00

I’m trying to develop a way of switching Windows Phone 7 application style depending

  • 0

I’m trying to develop a way of switching Windows Phone 7 application style depending on a setting.
The styles look like this:

  • core styles are separated and defined in WP7Style_Dark.xaml and WP7Style_Light.xaml
  • the rest of the styles are declared in Styles.xaml

I use the following code to hook up the themes in App.xaml.cs:

var dictionaries = Resources.MergedDictionaries;
dictionaries.Clear();
string source = String.Format("/CommonUI;component/Resources/{0}.xaml", value == AppStyleSet.Light ? "WP7Style_Light" : "WP7Style_Dark");
//base styles
var themeStyles = new ResourceDictionary {Source = new Uri(source, UriKind.Relative)};
dictionaries.Add(themeStyles);
var generalStyles = new ResourceDictionary();
generalStyles.Source = new Uri("/CommonUI;component/Resources/Styles.xaml",UriKind.Relative);
dictionaries.Add(generalStyles);

When executing, setting generalStyles.Source throws an exception (which is a System.Exception stating ‘Unspecified error’). I’ve discovered the exception goes away if I empty the Styles.xaml, but this is not a solution, of course.

What should I do?

Update 2: screw the stack trace, here’s the problem narrowed down:

The theme styles define theme colors.
The general styles keep loading fine until they meet a binding, like this one

... <Setter Property="Color" Value="{StaticResource HighlightColor}" />

So, the StaticResource fails to be resolved and throws the exception. Can this be avoided somehow?

  • 1 1 Answer
  • 0 Views
  • 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-18T06:46:51+00:00Added an answer on May 18, 2026 at 6:46 am

    The problem I’ve found with this approach is that there seems to be some asynchronicity about how the resource dictionary loads itself from the URL in the Source property. Hence when one dictionary uses {StaticResource key} where key is in a previous dictionary it can fail.

    One solution solution would be to extract the Xaml using Application.GetResourceStream and StreamReader. Then to use XamlReader to construct the ResourceDictionary. That way you can be sure that dependant dictionaries can find static resources they need.

    Note you would need to ensure you have added each dictionary where so that it is part of the Application.Resources tree before loading additional dependant dictionaries.

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

Sidebar

Related Questions

No related questions found

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.