Possible Duplicate:
Inheriting from a UserControl in WPF
I’m trying to create a WPF user control, which is derived from an other user control, which I also have defined.
<myNamespace:NavigationControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:myNamespace="clr-namespace:myNamespace" mc:Ignorable="d"
x:Class="myNamespace.WelcomeScreen"
x:Name="UserControl"
d:DesignWidth="640" d:DesignHeight="480">
and here’s what WelcomeScreen.cs looks like:
public partial class WelcomeScreen : NavigationControl
{
public WelcomeScreen()
{
this.InitializeComponent();
}
}
When I compile this, I get following error:
‘myNamespace.NavigationControl’ cannot be the root of a XAML file because it was defined using XAML.
What am I doing wrong?
You are not meant to do that and the error tells you that.
Besides, using XAML you set the
Content, if you set it again in your derived control you would lose everything you defined before. If you want inheritance and reusability use a custom control (and create a respectiveControlTemplate).