4

我正在创建一个资源字典,我在其中引用了所有转换器,因此无需引用每个单独的转换器。我的转换器位于不同的程序集中,要导入它们,我执行以下操作:

  1. 添加对外部程序集的引用
  2. 创建资源字典
  3. 添加引用转换器程序集的 xml 命名空间
  4. 参考转换器

所以我的字典看起来像:

    <ResourceDictionary xmlns:Converters="clr-namespace:Client.Utilities.Converters;assembly=Client.Utilities">

    <Converters:BoolToBrushConverter x:Key="boolToBrush"/>

</ResourceDictionary>

但是,在尝试构建时出现以下异常:

Error   18  The tag 'BoolToBrushConverter' does not exist in XML namespace 'clr-namespace:Client.Utilities.Converters;assembly=.Client.Utilities'. Line 12 Position 6.  C:\Resources.Tests\Resources\ResourceDictionaries\Converters\ConvertersResources.xaml   12  6   Client.eZenith.Resources.Tests

任何想法为什么会这样?

注意:从智能感知看来,转换器程序集的命名空间是正确的,因为所有转换器在键入后都会显示在建议列表中<Converter:

编辑:在渲染控件预览时,VS 和混合设计器都能够找到该转换器。

编辑:我已经弄清楚,这与合并字典无关。将转换器添加到Window 的 Resources时,会出现同样的问题。

4

2 回答 2

1

I have found the problem eventually, it is merged resourcedictionary bug introduce in .NET 4.

I have fixed it by adding an empty style into the merged resource dictionary (previously I had a RD where I was merging other RD and nothing else).

here is a blog post which I found recently which describes the same problem.

于 2011-06-27T09:34:02.047 回答
0

尝试使用

<ResourceDictionary xmlns:Converters="clr-namespace:Client.Utilities.Converters;assembly=Client.Utilities">

反而。
更改:clr-namespace而不是namespace.

于 2011-05-17T09:11:46.030 回答