Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
872 views
in Technique[技术] by (71.8m points)

wpf - adding a custom namespace to 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"

I want to use the LibNameSpace:Class1 class, and I was hoping to write myns:Class1 for this. However, that command causes this error:

Undefined CLR namespace. The 'clr-namespace' URI refers to a namespace 'LibNameSpace' that is not included in the assembly.

How can I fix this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Update:

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...