In our application there is a “basic” layout for all views. To reuse common code, I have crated a BaseControl class and a template for it.
What I want to achieve is a common title and a footer bar for every control derived from “BaseControl”
concrete view in XAML:
<my:BaseControl x:Class="SampleView"
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"
mc:Ignorable="d"
xmlns:my="clr-namespace:UserInterface" d:DesignWidth="924">
<Grid>
//This elements are not visible - why?
</Grid>
Common base class (no XAML but template)
public class BaseControl : System.Windows.Controls.UserControl{}
Template:
<Style TargetType="{x:Type my:BaseControl}" BasedOn="{StaticResource {x:Type UserControl}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
....snip
<Border Grid.Row="0" Name="SomeCommonUsedBorder">
<ContentPresenter>
//every thing placed between
//<SampleView> and </SampleView> should go here
</ContentPresenter>
....snip
//some other commonly used elements goes here
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The sample view looks like expected, but every thing I write inside the derived Control is not visible.
Thank you for any hints and ideas
Manuel
After some minutes after posting this question I found the answer.
I have to define the TargetType for the ControlTemplate. Otherwise the TargetType is Control. And Control itself does not have a Content property.