我想为我的应用程序定义多个主题,并在每次喜欢时切换它们,但我想将每个主题的每个控件的样式放在单独的ResourceDictionary
中,以便使文件具有务实的风格,并且我可以快速轻松地管理它们。 但问题是:嵌套资源字典的样式不适用。 有什么建议吗? 谢谢。嵌套资源字典
Q
嵌套资源字典
0
A
回答
2
我假定您为每个控件使用了单独的资源字典,并为其他主题重复使用它。 因此,我建议你保持一个资源字典为每个主题如:Theme1.xaml ..并合并其来在这个主题下你所有的资源字典.. 例如:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/UrProject;component/Themes/Theme1/Button.xaml"/>
<ResourceDictionary Source="pack://application:,,,/UrProject;component/Themes/Theme1/Combobox.xaml" />
<ResourceDictionary Source="pack://application:,,,/UrProject;component/Themes/Theme1/ListBox.xaml" />
<ResourceDictionary Source="pack://application:,,,/UrProject;component/Themes/Theme1/Checkbox.xaml" />
</ResourceDictionary.MergedDictionaries>
您可以添加并将此资源字典移除到您的应用程序以切换主题。希望能帮助到你。 :)
0
您可以将主题应用程序这样的..
public static void ApplyTheme(string themeName)
{
if (string.IsNullOrEmpty(themeName) == false)
{
bool exist = false;
string themeFileName =
string.Format("/UrProject;component/Styles/{0}{1}", themeName, ".xaml");
theme.Source = new Uri(themeFileName, UriKind.RelativeOrAbsolute);
foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries)
{
if (string.Equals(dictionary.Source, themeFileName))
{
exist = true;
break;
}
}
if (exist == false)
{
Application.Current.Resources.MergedDictionaries.Add(theme);
}
}
}
相关问题
- 1. 嵌套资源
- 2. form_for嵌套资源
- 3. 嵌套字典
- 4. Rails的路线,有嵌套的资源没有嵌套资源
- 5. Rails嵌套资源的嵌套布局
- 6. 的Rails的form_tag嵌套嵌套资源
- 7. 多资源字典
- 8. Python嵌套字典
- 9. 从嵌套字典
- 10. Python嵌套字典
- 11. 嵌套字典C#
- 12. C#嵌套字典
- 13. 的嵌套字典
- 14. REST和嵌套资源
- 15. flask-restul嵌套的资源
- 16. 轨路由嵌套资源
- 17. 嵌套资源路由
- 18. will_paginate链接嵌套资源
- 19. 路由和嵌套资源
- 20. 导轨和嵌套资源
- 21. 是否嵌套资源
- 22. 嵌套资源路径
- 23. 的form_for嵌套资源
- 24. Rails3中 - 嵌套资源
- 25. 嵌套资源,Ajax请求
- 26. Rails best_in_place嵌套资源gem
- 27. activeadmin:嵌套资源belongs_to的
- 28. 轨,path_names和嵌套资源
- 29. 的Rails 3 - 嵌套资源
- 30. 递归Rails嵌套资源
感谢名单,我已经做了同样的,没有例外,但风格并不适用。 – Mohsen 2012-02-23 06:04:01
如何将主题应用于应用程序?你可以发布代码.. – vimal 2012-02-23 06:17:10
代码是完全一样XAML美国的书面,但风格不适应 – Mohsen 2012-02-23 08:26:56