How to show a data template on a content control?
You can specify one of your templates on lower level. Something like:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<DataTemplate DataType="{x:Type ContentControl}" x:Key="T1">
<StackPanel>
<TextBox Height="20" />
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<ContentControl Template="{StaticResource T1}">
<ContentControl.Resources>
<DataTemplate DataType="{x:Type ContentControl}" x:Key="T2">
<StackPanel>
<TextBox Height="20" />
<TextBox Height="20" />
</StackPanel>
</DataTemplate>
<ContentControl.Resources>
</ContentControl>
</Grid>
</Window>
Instead of setting the Template
property, try this:
<ContentControl ContentTemplate="{StaticResource T1}" />