我试图根据设置开发一种切换Windows Phone 7应用程序样式的方法。 的风格是这样的:在运行时添加ResourceDictonary时出现异常
- 核心样式分离,并在WP7Style_Dark.xaml和WP7Style_Light.xaml定义
- 的风格其余宣布Styles.xaml
我用的是下面的代码挂钩主题在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);
当执行,设定generalStyles.Source抛出异常(这是一个系统.Exception指出'未指定的错误')。我发现如果我清空Styles.xaml,异常消失,但这当然不是解决方案。
我该怎么办?
更新2:螺丝堆栈跟踪,这里是缩小的问题:
主题风格定义主题颜色。 总体风格保持加载罚款,直到他们满足绑定,像这样的
... <Setter Property="Color" Value="{StaticResource HighlightColor}" />
所以,静态资源未能得到解决,并抛出异常。这可以以某种方式避免吗?
异常类型和内容似乎有点不足。你确定这种类型?有没有内部的例外? – Will 2010-11-09 13:08:48
这实际上是最近几个小时让我头疼的事情。我预计至少有一个XamlParseException,但唉。 – mcm69 2010-11-09 13:16:04