我开发了一个允许用户在主题之间切换的应用程序。我被包括XAML文件在我的项目资源,并使用下面的代码这样做:在Silverlight中使用资源字典作为主题
MainTheme.ThemeUri = new Uri("SilverlightApplication1;component/Themes/[ThemeName]/Theme.xaml", UriKind.Relative);
这个效果很好,直到我发现了以下主题:http://timheuer.com/blog/archive/2010/05/17/silverlight-4-tools-released-and-new-application-templates.aspx
不同的是,这些主题由多个文件组成。所以我制作了一个只包含MergedDictionaries的Theme.xaml文件,这样我仍然可以使用上面的代码。这是Cosmopolitan主题的Theme.xaml文件。
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="CoreStyles.xaml"/>
<ResourceDictionary Source="SDKStyles.xaml"/>
<ResourceDictionary Source="Styles.xaml"/>
<ResourceDictionary Source="ToolkitStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
然而,当我运行的C#代码上面,我得到以下异常:
System.Windows.Markup.XamlParseException: Failed to assign to property 'System.Windows.ResourceDictionary.Source'.
只是要清楚,使用MergedDictionaries方法不工作时,我把它在我的App.xaml:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Cosmopolitan/Theme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
我在做什么错?
谢谢!
我Theme.xaml文件中设置绝对路径也不起作用:( – SaphuA 2010-06-13 11:36:57
我有一个类似的问题原因是在引用文件时使用了反斜杠(\)而不是正斜杠(/).VS中的xaml解析器能够解析位置,但是在运行时会产生一个错误,希望这会帮助其他人out。 – 2011-08-09 18:26:47