【问题标题】:ResourceDictionary Merge behaviourResourceDictionary 合并行为
【发布时间】:2012-10-07 22:21:34
【问题描述】:

在我的项目中,我试图嵌入来自 Avalon Wizard 的源代码,但发生了一些奇怪的事情,我无法成功集成它。

我的自定义控件库中有以下结构

  • 向导
    • 主题
      • Aero.NormalColor.xaml
      • Aero2.NormalColor.xaml
      • AeroWizardHeader.xaml
      • Generic.xaml
      • Wizard97.xaml
      • WizardAero.xaml
      • Generic.xaml
  • 主题
    • Generic.xaml

在我的 Generic.xaml 中,我有以下声明

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="CuratioCMS.Client.UI;Component/Wizard/Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>

Wizard/Themes/Generic.xaml 里面是我定义 MergedDictionaries 的方式

    <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="CuratioCMS.Client.UI;Component/Wizard/Themes/Wizard97.xaml" />
    <ResourceDictionary Source="CuratioCMS.Client.UI;Component/Wizard/Themes/WizardAero.xaml" />
    <ResourceDictionary Source="CuratioCMS.Client.UI;Component/Wizard/Themes/AeroWizardHeader.xaml" />
</ResourceDictionary.MergedDictionaries>

根据 Avalon 的实现,在 Aero.NormalColor.xaml 中还提供了一个 MergedDictionary,看起来像这样

    <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="CuratioCMS.Client.UI;Component/Wizard/Themes/AeroWizardHeader.xaml" />
</ResourceDictionary.MergedDictionaries>

我的问题是我无法在我的项目中使用我自己的类库,因为设计器抛出异常:找不到资源'wizard/themes/curatiocms.client.ui;component/wizard/themes/ Wizard97.xaml'。

如果我更改 Wizard/Theme/Generic.xaml 中的路径,则错误消失,但 Wizard 无法提供 Aero 功能,甚至设计器也无法按预期工作。

我还要说,我决定采用这种架构是因为根据扩展的 WPF 工具包,这是一种非常干净的方式。

谁能帮我解决这个问题?

【问题讨论】:

  • 好的,我将 CuratioCMS.Client.UI;Component/Wizard/ 更改为 /CuratioCMS.Client.UI;Component/Wizard/ 所以我在开头添加了 / 符号,但仍然无法获得 Aero 效果我确定字典有问题,因为如果我将所有内容从 Wizard 文件夹中移出,它就可以工作

标签: wpf xaml custom-controls resourcedictionary


【解决方案1】:

您是否尝试过使用完整的pack URI syntax

您是否尝试过将“组件”更改为“组件”?还要确保字典的构建操作设置为 Resource 并且您正确引用了 CuratioCMS.Client.UI 程序集。

【讨论】:

  • 我尝试使用 Pack URI no result 将大写 C 更改为 c 也没有给出任何结果,你正确引用是什么意思?以及将哪个资源字典设置为资源而不是页面?如果我将所有字典构建操作编辑为资源,那么我会遇到 BooleanToVisibilityConverter' 的异常。'
  • 关于引用我们使用这个'CuratioCMS.Client.UI;component'的原因是为了引导当前程序集指向被引用的程序集。在包含 Generic.xaml 的项目中,确保 CuratioCMS.Client.UI 列在解决方案资源管理器的引用下。如果所有字典都在同一个程序集中,那么您不应该使用 'CuratioCMS.Client.UI;component'
  • 如果你看过扩展 WPF 工具包,我不明白你的意思,这是他们使用字典的方式。这也确保不会与其他程序集发生冲突,是的,generic.xaml 位于自定义用户控件库中,它也会包含其他控件
  • 关于构建操作,请参阅 msdn。 msdn.microsoft.com/en-us/library/aa350178.aspx
  • 使用扩展 WPF 工具包完成此操作的原因是因为它是作为引用程序集添加的。如果您查看参考资料,将显示 WPFToolkit。如果您尝试访问当前程序集中的资源字典,则不应使用“CuratioCMS.Client.UI;component”。它应该只是 Source=".​​./Wizard/Themes/AeroWizardHeader.xaml"
猜你喜欢
  • 2017-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多