WPF - 仅清除某些资源字典
我通过清除所有合并字典 (Resources.MergedDictionaries.Clear()) 和基于所选主题的新字典,将“主题”应用到我的 WPF 应用程序。
我不想清除所有字典,而是只想清除某些“与主题相关”的字典,而让其他字典仍然加载。我怎样才能做到这一点?我在迭代字典时没有找到区分字典的方法...
感谢您的帮助!
I am applying "themes" to my WPF app by clearing all merged dictionaries (Resources.MergedDictionaries.Clear()) and new ones based on the selected theme.
Instead of clearing all dictionaries, I would like to clear only certain "theme-related" dictionaries, leaving others still loaded. How can I do that? I didn't find a way to differentiate dictionaries when iterating though them...
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您正在
Application
级别进行合并,否则您可以只引入一个中间控件,其唯一的工作是托管主题字典。在这种情况下,我建议使用多层方法,其中第一个合并的字典包含所有与主题相关的字典:现在您可以使用如下代码仅定位与主题相关的资源:
I'm assuming you're doing the merging at the
Application
level, otherwise you could just introduce an intermediate control whose only job is to host the theme dictionaries. That being the case, I would suggest using a multi-tiered approach whereby the first merged dictionary houses all theme-related dictionaries:Now you can target only theme-related resources with code like this: