向xaml添加自定义名称空间 [英] adding a custom namespace to xaml

查看:191
本文介绍了向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.

我该如何解决?

推荐答案

名称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

更新:

程序集的名称可以在(库程序集的)项目的属性屏幕中的project-explorer中找到.通常,不带dll后缀的dll的文件名也代表程序集名称.

The name of the assembly can be found in project-explorer in the propeties-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屋!

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