简体   繁体   English

设计时资源词典

[英]Design-Time Resourcedictionaries

I have created something like this and this . 我创建像这样这个
In effect I have a dll which supplies me with a "styler" for my application - it contains all my basic styles as well as a factory to call StylerFactory.DefaultStyler.ApplyStyles(this) on an Application - which merges the supplied ResourceDictionaries with the existing. 实际上,我有一个为我的应用程序提供“样式器”的StylerFactory.DefaultStyler.ApplyStyles(this)它包含所有基本样式以及在应用程序上调用StylerFactory.DefaultStyler.ApplyStyles(this)的工厂-该工厂将提供的ResourceDictionaries与现有。 This way I don't need all the basic styles in my components, nor do I need explicit references to my sesource-xaml-files. 这样,我不需要组件中的所有基本样式,也不需要显式引用sesource-xaml文件。
Now - while this is working real good. 现在-虽然效果很好。 The Styles are (obviously) not visible during design-time To my questions: 在设计时(显然)看不到样式。对我的问题:

  1. Was that approach wise, or would it have been better to deploy xaml-resources and use them in every app/window/control ? 那是明智的选择,还是最好将xaml-resources部署并在每个应用程序/窗口/控件中使用它们?
  2. Does someone see any possibility to apply my styles to the design-time display of VS2008 ? 有人看到将我的样式应用于VS2008的设计时显示的可能性吗?

In my opinion, it's an acceptable approach. 我认为这是可以接受的方法。 The reason being, I haven't seen a better method. 原因是,我没有看到更好的方法。

In my own cases, I've loaded resource dictionaries at runtime using the code I described here , which I would assume would work for loading resources from other assemblies as well. 在我自己的情况下,我已经在运行时使用此处描述的代码加载了资源字典,我认为该代码也可以从其他程序集中加载资源。 The drawback is that the designer will not run this code first, meaning no style is applied by default, what you're experiencing. 缺点是设计人员不会首先运行此代码,这意味着默认情况下,您将遇到的样式不会应用。

To counteract this, I added a default <ResourceDictionary.MergedDictionaries> definition in each of my <Window.Resources> that I needed to edit at design-time. 为了解决这个问题,我在设计时需要编辑的每个<Window.Resources>中都添加了默认的<ResourceDictionary.MergedDictionaries>定义。 While this ends up being a bit redundant, this allowed me to have a working design-time Window while the proper MergedDictionary can be loaded later during runtime. 尽管这最终有点多余,但是这允许我拥有一个有效的设计时窗口,而稍后可以在运行时加载适当的MergedDictionary。 Perhaps you can use this to find a better method. 也许您可以使用它来找到更好的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM