You cannot inherit from a user control that has a XAML file. You need to create a plain C# class as the base class:
// File: A.cs
public class A : UserControl
{
public A()
{
// create your controls programmatically
}
}
Then in your sub class's XAML file:
// File: B.xaml
<local:A x:Class="WpfApp1.B"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
</Grid>
</local:A>
(replace WpfApp1
with your namespace, obviously)
Note that the root tag name is local:A
instead of UserControl
. This identifies your control's base class. The x:Class=...
part specifies the class name of the inherited user control.