CLR命名空间映射到默认XAML命名空间 [英] Clr namespace mapping to default xaml namespaces

查看:185
本文介绍了CLR命名空间映射到默认XAML命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点厌倦了在每一个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)
 

不过这似乎并没有工作。我仍然得到一个编译错误,如:

  

在'MyCustomControl标签没有在XML命名空间存在'http://schemas.microsoft.com/winfx/2006/xaml/$p$psentation。

注:我的控制是相同的组件内(我有一个程序集)

解决方案
  1. 不幸的是,你不能使用映射到 XmlnsDefinition 定义的XAML命名空间的控制,如果控制同一程序中定义。不同的组件做工精细,虽然。你必须使用 CLR命名空间定义这一点。

  2. 为什么要到你的控件添加到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:

The tag 'MyCustomControl' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.

Note: My controls are within the same assembly (I have a single assembly).

解决方案

  1. 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 the clr-namespace definition for this.

  2. 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 add using directives for their namespaces.

这篇关于CLR命名空间映射到默认XAML命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆