向 xaml 添加自定义命名空间 [英] adding a custom namespace to xaml
问题描述
我对 C#、WPF 和 XAML 还很陌生,所以我可能无法使用正确的术语来提出正确的问题 =)我正在尝试将我自己的命名空间添加到我的 xaml 文件中,以便轻松使用我自己的类 - 我猜原因是这个 -为此,我在窗口标签中编写了以下代码:
I am quite new on C#, WPF and XAML, so I may not be able to use the right terms to ask the right question =) I am trying to add my own namespace to my xaml file in order to use my own class easily -I guess the reason is this- I wrote the following code in window tag for this:
xmlns:myns="clr-namespace:LibNameSpace"
我的窗口标签也以以下定义开头:
Where my window tag also starts with the following definition:
< Window x:Class="LibNameSpace.MainWindow"
我想使用 LibNameSpace:Class1
类,我希望为此编写 myns:Class1
.但是,该命令会导致此错误:
I want to use the LibNameSpace:Class1
class, and I was hoping to write myns:Class1
for this. However, that command causes this error:
未定义的 CLR 命名空间.clr-namespace" URI 指的是程序集中未包含的命名空间LibNameSpace".
Undefined CLR namespace. The 'clr-namespace' URI refers to a namespace 'LibNameSpace' that is not included in the assembly.
我该如何解决这个问题?
How can I fix this?
推荐答案
LibNameSpace 这个名字听起来像是另一个程序集中的库.如果是这种情况,您必须添加程序集的名称:
The name LibNameSpace sounds like its a library in another assembly. If this is the case, you must add the name of the assembly:
xmlns:myns="clr-namespace:LibNameSpace;assembly=MyLibAssembly
更新:
程序集的名称可以在项目(库程序集)的属性屏幕中的项目资源管理器中找到.一般来说,不带 dll
-suffix 的 dll 的文件名也代表程序集名称.
The name of the assembly can be found in project-explorer in the properties-screen of the project (of the library-assembly). In general also the file-name of the dll without the dll
-suffix represents the assembly name.
这篇关于向 xaml 添加自定义命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!