Hi, it's impossible inherit one UserControl from another UserControl. Implicitly a WPF UserControl inherits from base class UserControl. In C# you cannot inherit from 2 classes like in C++. For Inheritance you must use CustomControls. On every inheritance level you include design via Style.
Try following demo (base control with DepenencyProperty, inherited control with bounded Label, MainWindow with used property):
Base control:
using System.Windows;
using System.Windows.Controls;
namespace WpfControlLibrary1
{
public class Window36CC1 : Control
{
static Window36CC1()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Window36CC1), new FrameworkPropertyMetadata(typeof(Window36CC1)));
}
public Window36CC1()
{
this.DataContext = this;
}
public string Info
{
get { return GetValue(InfoProperty).ToString(); }
set { SetValue(InfoProperty, value); }
}
public static readonly DependencyProperty InfoProperty =
DependencyProperty.Register("Info", typeof(string), typeof(Window25UC3),
new PropertyMetadata(string.Empty));
}
}
Inherited control:
using System.Windows;
namespace WpfControlLibrary1
{
public class Window36CC2 : Window36CC1
{
static Window36CC2()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Window36CC2), new FrameworkPropertyMetadata(typeof(Window36CC2)));
}
}
}
And Generic.xaml:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfControlLibrary1">
<Style TargetType="{x:Type local:Window36CC1}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Window36CC1}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type local:Window36CC2}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Window36CC2}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<Label Content="{Binding Info}"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
MainWindow:
<Window x:Class="WpfApp1.Window36"
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:local="clr-namespace:WpfApp1"
xmlns:uc="clr-namespace:WpfControlLibrary1;assembly=WpfControlLibrary1"
mc:Ignorable="d"
Title="Window36" Height="450" Width="800">
<Grid>
<uc:Window36CC2 Info="TestText"/>
</Grid>
</Window>
Result: