I am trying to develop a way to switch the style of a Windows Phone 7 application depending on the setting. The styles are as follows:
- The main styles are separated and defined in WP7Style_Dark.xaml and WP7Style_Light.xaml
- other styles are declared in Styles.xaml
I use the following code to connect 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");
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 installing, generalStyles.Source throws an exception (which is a System.Exception message with the message "Unspecified error"). I found that the exception disappears if I release Styles.xaml, but that is not the solution, of course.
What should I do?
Update 2: unscrew the stack trace, here the problem has narrowed:
.
, ,
... <Setter Property="Color" Value="{StaticResource HighlightColor}" />
, StaticResource . - ?