我正在创建一个资源字典,在其中引用所有转换器,因此无需引用每个单独的转换器。
我的转换器位于不同的程序集中,要导入它们,我执行以下操作:
- 添加对外部程序集的引用
- 创建资源字典
- 添加引用转换器程序集的 xml 命名空间 引用
- 转换器
所以我的字典看起来像:
<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
有什么想法为什么会发生这种情况吗?
注意:从智能感知来看,转换器程序集的命名空间似乎是正确的,因为输入
Edit:VS和混合设计器都能够在渲染控件预览时找到该转换器。
编辑:我发现,这与合并字典无关。将转换器添加到Windows 资源时,也会出现同样的问题。
I am creating a Resource Dictionary, where I reference all my converters, so there is no need to reference each individual converter.
My converters are in the different assembly, to import them I do the following:
- Add reference to external assembly
- Create a Resource Dictionary
- Add xml namespace referencing Converters assembly
- Reference converters
So my Dictionary looks like:
<ResourceDictionary xmlns:Converters="clr-namespace:Client.Utilities.Converters;assembly=Client.Utilities">
<Converters:BoolToBrushConverter x:Key="boolToBrush"/>
</ResourceDictionary>
However I get the following exception when trying to build:
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
Any ideas why that is happening?
Note: From intellisense it seems that namespace for Converters assembly is correct, as all converters show up in the suggestion list after typing <Converter:
Edit: VS and blend designer both are able to find that converter, when rendering control preview.
Edit: I have figured out, that it is nothing to do with dictionaries being merged. The same issue appears, when adding a converter to Window's Resources.
发布评论
评论(2)
我最终发现了问题,它是.NET 4中引入的合并资源字典错误。
我通过在合并资源字典中添加一个空样式来修复它(之前我有一个RD,我在其中合并其他RD而没有其他东西)。
这里是我最近发现的一篇博客文章,描述了同样的问题。
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.
尝试使用
代替。
更改:
clr-namespace
而不是namespace
。Try using
instead.
Change:
clr-namespace
instead ofnamespace
.