Add Class Library to WPF project

Hi I created Class Library which works if it's added to the project as a complete project. I can call it from demo like this:
 xmlns:control="clr-namespace:MyCustomControls;assembly=MyCustomControls"
How can I add it as a dll to the project ?
I did like this:
1. Add reference to library (to MyCustomControls.dll)
2.   xmlns:control="clr-namespace:MyCustomControls;assembly=MyCustomControls"
Nothing happens when I run the application.
What I do wrong?
LVL 1
mastiSoftAsked:
Who is Participating?
 
Chinmay PatelConnect With a Mentor Enterprise ArchitectCommented:
If you really need to create a custom interface for your forms, I strongly suggest you use: https://github.com/MahApps/MahApps.Metro

either as a base to start OR entire project itself.

Now coming to the second part of your query, You have function xyz in assembly MyAssembly. You have a project MyProject and you want to consume functionality from MyAssembly.

Now if you just want to call the function xyz and get the result back, after adding the references, you can instantiate the class like this

MyAssembly assembly = new MyAssembly();
assembly.xyz();

If you want to provide a UI from your assembly, I suggest you read this articles from Microsoft's documentation https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/control-authoring-overview
and also check this Walk-through https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/walkthrough-create-a-button-by-using-xaml
1
 
Chinmay PatelEnterprise ArchitectCommented:
Both the two points you have mentioned are just referencing your assembly, you have to call a method or create an instance of a class from your assembly. What exactly your Assembly does?
0
 
mastiSoftAuthor Commented:
it creates a custom interface for form.  Here I send two screen shots. One is the output and the second is how it is woks (when the project is a part of another project)
Capture.PNG
HereItWorks.PNG
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
MishaProgrammerCommented:
May ne you should add your controls from your library in your base project(form)?
Also may be some problmes in your dll?

Do you  change  on Application tab Output type from Windows Application to Class Library

Do you select WPF > User Control (WPF), when you add your dll to your project? (To use XAML add reference to Windows.XAML assembly (Project > right click on References > Add Reference > from Assemblies add Windows.XAML ))

Also you should use this code in your main project:
<Window  
xmlns:lib="clr-namespace:MyCustomControls;assembly=MyCustomControls"
>
<lib:UserControl1 /> <!-- your Control from the library -->
</Window>

Open in new window

0
 
mastiSoftAuthor Commented:
we can forget about my control and talk in general. I have another one  the one I know is works I renamed it to be able add as attached file (it is not txt but dll)
I put the dll file into bin/Debug and add reference to this dll
in C# I include using MyCustomControls;
How do I apply this user control to my .xaml to apply this control to my project? Do I have to add something to App.xaml or what?
I was looking in Internet but all I find is how to create the User Control not how to use existing.
MyCustomControls.txt
0
 
MishaProgrammerCommented:
Why you add your dll in folder bin/Debug ? When you compile your project, library usually are copied in this folder. It is better, if you create own folder, for example, "Mylibrary", put there your dll and then add reference to this dll.
0
 
mastiSoftAuthor Commented:
I added the reference to dll and added dll to the project. Nothing helps. It have to exist tutorial about how to add user control to WPF project but I can't find it.
Screen-Shot-04-07-18-at-01.55-PM.PNG
0
 
mastiSoftAuthor Commented:
thank you very much Mr.Chinmay Patel.
0
 
Chinmay PatelEnterprise ArchitectCommented:
Glad I could help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.