starkshang
starkshang

Reputation: 8578

namespace not found in xaml, but can be used in C# code

I have a WPF Project Home,it will reference a library project which defines namespace 'LibraryProjectExample', I want to use it in the Home Project,the namespace can not be found:

xmlns:view="clr-namespace:LibraryProjectExample"

But when I use using namespace LibraryProjectExample in C# code,I can use it normally.

I have checked that the LibraryProject has been referenced by the Home Project, I don't know why i can't use the namespace in xaml.Anyone can tell me,thanks!

Upvotes: 0

Views: 3971

Answers (3)

mm8
mm8

Reputation: 169390

Besides the namespace you should also specify the name of the library project/assembly where the namespace is defined:

xmlns:view="clr-namespace:LibraryProjectExample;assembly=LibraryProject"

You need to change "LibraryProject" in the above sample markup to the actual name of the referenced project where the "LibraryProjectExample" namespace is defined.

Upvotes: 1

Ada Orajiaku
Ada Orajiaku

Reputation: 146

It looks like you're not adding the assembly to your xaml reference. Look in your LibraryProjectExample project and find it's package name, then you can append it to your namespace declarationlike so xmlns:view="clr-namespace:LibraryProjectExample;assembly=YOUR_PACKAGE_NAME"

Upvotes: 2

Chandresh Khambhayata
Chandresh Khambhayata

Reputation: 1777

You have to use as below in you Xaml page.

xmlns:object="clr-namespace:**namespace**;assembly=*assembly*"

here namespace is your packagename.classname and assembly is your packagename

For Example, xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"

Thank You.

Upvotes: 3

Related Questions