Silverlight 4.0 在Silverlight中将资源字典用作主题
我开发了一个应用程序,允许用户在主题之间切换。为此,我将xaml文件作为资源包含在项目中,并使用以下代码:Silverlight 4.0 在Silverlight中将资源字典用作主题,silverlight-4.0,themes,resources,Silverlight 4.0,Themes,Resources,我开发了一个应用程序,允许用户在主题之间切换。为此,我将xaml文件作为资源包含在项目中,并使用以下代码: MainTheme.ThemeUri = new Uri("SilverlightApplication1;component/Themes/[ThemeName]/Theme.xaml", UriKind.Relative); 这很有效,直到我发现这些主题: 不同之处在于,这些主题由多个文件组成。因此,我制作了一个Theme.xaml文件,其中只包含合并字典,因此我仍然可以使用上面的代
MainTheme.ThemeUri = new Uri("SilverlightApplication1;component/Themes/[ThemeName]/Theme.xaml", UriKind.Relative);
这很有效,直到我发现这些主题:
不同之处在于,这些主题由多个文件组成。因此,我制作了一个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>
需要明确的是,在我的App.xaml中设置MergedDictionaries方法时,它确实有效:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Cosmopolitan/Theme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
我做错了什么
谢谢 使用MergedDictionary时,必须使用完全限定名,如下所示
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/SilverlightApplication1;component/Themes/Cosmopolitan/Theme.xaml"/>
不像
Source="SilverlightApplication1;
HTH在我的Theme.xaml文件中设置绝对路径也不起作用:(我遇到了类似的问题,原因是使用反斜杠()而不是正斜杠(/)引用文件时。VS中的xaml解析器能够解析该位置,但在运行时生成了一个错误。希望这能帮助其他人解决问题。您不必在程序集名称“/SilverlightApplication1;component/Themes/Cosmopolitan/Theme.xaml”后加上“component”王子:组成部分是必不可少的。请考虑更新你的答案。这将是一个很好的答案后,更新。
Source="/SilverlightApplication1;
Source="SilverlightApplication1;