我有点厌倦了必须在每个 xaml 文件中声明一个 xmlns 并且必须为我的自定义控件使用前缀。是否可以将 clr 命名空间映射到“http://schemas.microsoft.com/winfx/2006/xaml/presentation”?
我在 AssemblyInfo.cs 中尝试了以下操作:
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation","MyOwnNamespace")]
但这似乎行不通。我仍然遇到编译错误,例如:
The tag 'MyCustomControl' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.
注意:我的控件在同一个程序集中(我只有一个程序集)。
最佳答案
遗憾的是,如果这些控件是在同一个程序集中定义的,则您不能使用映射到由
XmlnsDefinition
定义的 Xaml 命名空间的控件。不过,不同的程序集工作正常。为此,您必须使用clr-namespace
定义。为什么要将控件添加到 Xaml 默认命名空间?不要这样做。这就像为您的类使用
System
命名空间,因为您不想为其命名空间添加using
指令。
关于c# - Clr 命名空间映射到默认 xaml 命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11335271/