Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created and compiled a WPF UserControl Library using VS 2008 .NET 3.5 on a Vista machine.
Then I created a simple WPF Windows application. I added a reference to the compiled UserControl Library. Now when I try to a namespace in the XMAL code for the window I do not see my compiled UserControl namespace.
What am I missing?
Posted
Updated 27-Nov-10 8:36am
v3
Comments
JF2015 27-Nov-10 12:59pm    
Edited to remove <pre> tag since they are supposed to be used for code only.
Henry Minute 27-Nov-10 13:31pm    
Did you add a namespace reference (xmlns) in your .xaml file?

After you've added the reference, you can call the UserControl directly from the code behind, like this:
C#
public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Content = new WpfControlLibrary1.UserControl1();
        }
    }


If you want to use it from the XAML code, use this:
XML
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:lib="clr-namespace:WpfControlLibrary1;assembly=WpfControlLibrary1"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <lib:UserControl1 />
    </Grid>
</Window>


The xmlns:lib attribute of the Window element, maps the xml namespace lib to the WpfControlLibrary1 namespace. This is the syntax:
xmlns:{name}="clr-namespace:{namespace};assembly={assembly}"

I hope this helped you!

PS:
remember to recompile the whole solution, otherwise, the IntelliSense won't be able to detect the new namespace!
 
Share this answer
 
Comments
Tarun.K.S 28-Nov-10 1:43am    
Good Answer!
69Icaro 28-Nov-10 5:11am    
Thanks! I'm very happy when I can help people!
Tarun.K.S 28-Nov-10 12:33pm    
Great! have a 5!
69Icaro 29-Nov-10 16:20pm    
Thanks!
Thanks 691caro and the rest. I have done exactly what 691caro suggested and it doesn't work. my compiled dll is external to the current solution. If I run the app, it works. But the problem is that I do not see my namespace to insert it in the xaml file. is that normal behaviour? and also, as soon as I manually add the namespace the designer complains that I cannot load, is this a problem with visual studio 2008.
Also, do you guys have or can direct me where I can take a look at some smaple code showing the use of a UserControl using data binding to a business object, say a person object, and which uses DependencyProperty properties? The examples I have seen about UserControls and databinding using DependencyProperty properties 99% of them only have one property. I would like to see one that uses a customer or a person object, something more realistic.

Thank you in advance. I really appreciate it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900