views:

93

answers:

2

i am quite new on c#, wpf and xaml etc then 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 that command in window tag for this: xmlns:myns="clr-namespace:LibNameSpace" where my window tag also starts with < Window x:Class="LibNameSpace.MainWindow"... definition and i want to use the LibNameSpace:Class1 class, and was hoping just to write myns:Class1 for this. and this command causes that 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? thanks for helping=)

+2  A: 

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 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.

HCL
well, in deed i saw such a solution from somewhere but i didn't know from where to learn the name of my assembly...=)
cemregoksu
Any other suggestion/ idea/ help??
cemregoksu
i am afraid it doesn't work when i write xmlns:myns="clr-namespace:LibNameSpace;assembly=LibNameSpace"
cemregoksu
Does your Assembly name contain any spaces? You should add a underscore for spaces I guess.
Ingó Vals
it's funny that when i tried to write the full name such as "clr-namespace..." by hand it didnt work but when i just picked the namespace from the intellisense list, it worked...thanks for help=)
cemregoksu
A: 

Because for me it's not really clear what you want to do, here another try:

If MyLibAssembly is the main namespace of your application and there in you have a Window named MainWindow and a class named Class1 that you want to instantiate in your MainWindow-class:

  • Make sure, that in Class1 is no error, the project must compile without errors. Remove first the namespace-declaration from the xaml and compile your project till you have no compilation errors.
  • Make sure that Class1 is public and has a paramterless constructor
  • Make sure that in the code behind your MainWindow is also in the MyLibAssembly-namcespace.
  • Add then the namspace-declaration xmlns:local="clr-namespace:LibNameSpace into your xaml. local is generally used to declare the same namespace as your current element, in your case the window, is in.
  • Insert your Class1 with the <local:Class1/> -tag in the xaml. If Class1 does not derive from FrameworkElement or a higher level control, you must add it into the resources-section of your window. If this is true, give it a key. <local:Class1 x:Key="KeyToYourClass"/>

Maybe vs is out of sync. Click in the solution-explorer on the root-node Clean Solution and then Rebuild Solution. Maybe that helps.

I hope this helped. If not, try to reformat your question (use the code-symbol to make the question more readable and try to rephrase to make more clear what your desire is).

HCL