How to add a User Control to your WPF Window

In the window XAML add the namespace of your control. So, if your control is called MyControl and your project is called MyProj then most likely the full namespace is MyProj.MyControl.

The control might look like this:

<UserControl
x:Class=MyControl


xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation


xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml>

    <DockPanel>

        <Button>Test</Button>

        <Button>Test</Button>

        <Button>Test</Button>

        <Button>Test</Button>

    </DockPanel>

</UserControl>

 

Your form header will look like this:

<Window
x:Class=Window1


xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation


xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml

    xmlns:l=clr-namespace:MyProj


Title=wpf
Height=300
Width=300

>

Then to use the control you will do this:

<l:MyControl></l:MyControl>

I got this to work in VS 2005 with WPF Extensions but I cannot get it to work in Orcas March CTP… The project compiles and runs fine in both cases, but the control will just not show up in the Orcas version!!! Any ideas?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s