How to add a User Control to your WPF Window
March 9, 2007
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?
Posted in

content rss

Add New Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks