Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add my UserControl from another project (Dll) into my WPF Solution?

So, everything is in the title, I just want to add a UserControl in my WPF Window. It looks like easy but the UserControl is in another project (Dll project) in the same solution. And I just can't reference it.

So, my best try is something like that:

<Window xmlns:local="clr-namespace:MyWindowProject" x:Name="window"
    xmlns:other="clr-namespace:MyDllProject"
    x:Class="MyWindowProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
    <other:MyUserControl />
</Window>

I know I am near to find how to make it because I've got just one error and the autocompletion is working on MyUserControl. But, I've got this weird error: "The name 'MyUserControl' does not exist in the namespace "clr-namespace:MyDllProject".

I'm sure that I'm doing something wrong, but I really don't know what...

like image 639
Marc Avatar asked Jul 02 '13 10:07

Marc


People also ask

What is the difference between UserControl and window in WPF?

A window is managed by the OS and is placed on the desktop. A UserControl is managed by wpf and is placed in a Window or in another UserControl. Applcations could be created by have a single Window and displaying lots of UserControls in that Window.

Can we have multiple user controls in WPF?

Adding Multiple Controls to the Content Panel | Basic Library for WPF and Silverlight | ComponentOne. You cannot set the Content property to more than one control at a time.

How do I add user control to XAML?

Using a user control in XAML is pretty simple. I use a WPF Application to test the control. Create a WPF application project and copy the control code files to your project. After that, you need to add namespace of the library in which the user control is defined.

What is UserControl WPF?

User controls, in WPF represented by the UserControl class, is the concept of grouping markup and code into a reusable container, so that the same interface, with the same functionality, can be used in several different places and even across several applications.


2 Answers

xmlns:other="clr-namespace:MyDllProject"

The above import statement show's that you are pointing the namespace of your local project. if you want to add a refrance of the other project (The Dll Project) then you must add the namespace as like

xmlns:other="clr-namespace:MyDllProjectNamespace;assembly=MyDllProject"

This will point the namespace which exists in Other assembly.

See this Article to understand the namespaceing in Xaml

Condition Make sure the using control is accessible from the other assemblies.

like image 87
JSJ Avatar answered Sep 18 '22 22:09

JSJ


Add your user control to the controls tool box, and drag'n drop from there to your form. Visual Studio will take care of namespaces and things like that.

like image 20
Oscar Avatar answered Sep 20 '22 22:09

Oscar