edward_mellor
asked on
Adding a User Control to a Window all in the same Visual Studio project
I just cannot work this out, I know it is very simple if you are familiar with WPF.... I have a window and a user control both in the same Visual Studio 2008 project. How do I add the user control as a child in Window?
--------------------------------------------------------------------------------
Window XAML
--------------------------------------------------------------------------------
<Window x:Class="TextBannerTestApplication.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:uc="clr-namespace:TextBanner;assembly=TextBanner"
Title="Window1" Height="400" Width="1000" Background="Red">
<StackPanel>
<StackPanel Orientation="Horizontal" Height="30">
<Button x:Name="btn1" Content="Test 1" Click="btn1_Click" />
<Button x:Name="btn2" Content="Test 2" Click="btn2_Click" />
<Button x:Name="btn3" Content="Test 3" Click="btn3_Click"/>
<Button x:Name="btn4" Content="Test 4" Click="btn4_Click"/>
</StackPanel>
</StackPanel>
</Window>
--------------------------------------------------------------------------------
User Control XAML
--------------------------------------------------------------------------------
<UserControl x:Class="TextBannerTestApplication.UserControlTextBanner"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid>
<Button Margin="61,117,71,141" Name="buttonTest">Test 1 2 3</Button>
</Grid>
</UserControl>
ASKER
It is the user control UserControlTextBanner that I want add the the window. This user control is in the same project as the window.
From the code you have provided I have created a sample project I am attaching it with this post. I have take freedom to change some properties like background and etc.
Let me know if this is what you are looking for.
Thanks
Let me know if this is what you are looking for.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did it help ?
If that is the case , I see you have already added reference to the user control in your window.
Just add this line after your btn4 to have it in your Window
<uc:UserControl x:Name="yourcontrol"></uc: