c# - 为什么 XAML(WPF) 不在我的 XML 命名空间定义中搜索控件?

标签 c# xml wpf xaml silverlight

我有两个类似的项目。一个是 Silverlight 项目,另一个是 WPF。它们都包含一些命名空间和大量自定义用户控件。

由于控件分布在许多 namespace 中,因此在使用它们时我必须定义相当多的 namespace 。所以我开始define the XML namespaces in the AssemblyInfo.cs :

[assembly: XmlnsPrefix("http://ui.example.com/xaml/touch", "cui")]
[assembly: XmlnsDefinition("http://ui.example.com/xaml/touch", "example_ui.controls")]
[assembly: XmlnsDefinition("http://ui.example.com/xaml/touch", "example_ui.themes")]

现在我只需要在每个文件中定义一个命名空间:

xmlns:cui="http://ui.example.com/xaml/touch"

不幸的是,这适用于 Silverlight。我的问题是,如何让它在 WPF 项目中工作?

在 WPF 项目中我得到这样的错误:

Error   5   The tag 'LookUpField' does not exist in XML namespace
   'http://ui.example.com/xaml/touch'. Line 7 Position 14.  D:\src\prototype\lookup-control\lookup-control\MainWindow.xaml  7   14  lookup-control

最佳答案

虽然该教程适用于 Silverlight,但我认为它可能不适用于 WPF。查看已接受的答案 here .

我在 WPF 中有一个带有自定义控件的单独程序集,我可以使用 XmlnsDefinition属性没有问题。我认为问题在于在构建程序集之前需要存在的定义。因此,即使控件会出现在您的设计器中,也无法构建它,因为编译器在 BAML 中编译 XAML 时需要定义,即 built into the assembly at a later point。 .

编辑

我创建了另一个 WPF 用户控件库并添加了相同的 XmlnsDefinition如果你使用过,将用户控件库的引用添加到我的 WPF 应用程序项目中,使用过 <cui:UserControl1 />在我的 MainWindow.xaml并且没有错误。

关于c# - 为什么 XAML(WPF) 不在我的 XML 命名空间定义中搜索控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32087833/

相关文章:

c# - 计算多个线程中的东西

c++ - XML 文件格式中的 bool 值应该写成 true/false 还是 1/0?

WPF 更改网格和网格边框不透明度而不影响子项

c# - 使用 MySql 获取每个事件的正确价格

c# - Mono 上的 NServiceBus

c# - 为什么 TripleDES.Create().Key 不是该算法的有效大小?

javascript - Cypress - 使用 JQuery 对 XHR 请求的 XML 响应解析

Android 设置 - 反向依赖

c# - ComboBox 强制崩溃(不是我的代码)

c# - 反射权限异常