问题描述
我有点厌倦了在每一个XAML文件中声明了xmlns,不得不使用prefixes我的自定义控件。是否有可能一个CLR命名空间映射到http://schemas.microsoft.com/winfx/2006/xaml/$p$psentation?
我尝试了以下在我的AssemblyInfo.cs:
[总成:XmlnsDefinition(http://schemas.microsoft.com/winfx/2006/xaml/$p$psentation,MyOwnNamespace)
不过这似乎并没有工作。我仍然得到一个编译错误,如:
注:我的控制是相同的组件内(我有一个程序集)
-
不幸的是,你不能使用映射到
XmlnsDefinition
定义的XAML命名空间的控制,如果控制同一程序中定义。不同的组件做工精细,虽然。你必须使用CLR命名空间
定义这一点。 -
为什么要到你的控件添加到XAML默认命名空间?不这样做。这就像使用
系统
命名空间的类,因为你不希望添加使用
指令为他们的命名空间。
I'm a bit tired of having to declare an xmlns in every xaml file and having to use prefixes for my custom controls. Is it possible to map a clr namespace to "http://schemas.microsoft.com/winfx/2006/xaml/presentation"?
I tried the following in my AssemblyInfo.cs:
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation","MyOwnNamespace")]
but this doesn't seem to work. I still get a compile error like:
Note: My controls are within the same assembly (I have a single assembly).
Unfortunately, you cannot use controls mapped to a Xaml namespace defined by
XmlnsDefinition
, if the controls are defined in the same assembly. Different assemblies work fine though. You'll have to use theclr-namespace
definition for this.Why would you want to add your controls to the Xaml default namespace? Don't do this. It's like using the
System
namespace for your classes because you don't want to addusing
directives for their namespaces.
这篇关于CLR命名空间映射到默认XAML命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!