7

我有点厌倦了必须在每个 xaml 文件中声明一个 xmlns 并且必须为我的自定义控件使用前缀。是否可以将 clr 命名空间映射到“http://schemas.microsoft.com/winfx/2006/xaml/presentation”?

我在我的 AssemblyInfo.cs 中尝试了以下内容:

[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation","MyOwnNamespace")]

但这似乎不起作用。我仍然收到如下编译错误:

XML 命名空间“http://schemas.microsoft.com/winfx/2006/xaml/presentation”中不存在标记“MyCustomControl”。

注意:我的控件在同一个程序集中(我有一个程序集)。

4

1 回答 1

9
  1. XmlnsDefinition不幸的是,如果控件是在同一个程序集中定义的,则不能使用映射到由 定义的 Xaml 命名空间的控件。不同的组件虽然工作正常。您必须为此使用clr-namespace定义。

  2. 为什么要将控件添加到 Xaml 默认命名空间?不要这样做。这就像System为你的类使用命名空间,因为你不想using为它们的命名空间添加指令。

于 2012-05-11T11:10:35.623 回答