It’s that time again, trying to achieve trivial parts in WPF.
<Window.Resources>
<ControlTemplate x:Key="GroupBoxTemplate">
<GroupBox Header="ASD">
<ContentPresenter/>
</GroupBox>
</ControlTemplate>
</Window.Resources>
<Grid>
<ContentControl Template="{StaticResource GroupBoxTemplate}" >
<Button Content="test"/>
</ContentControl>
</Grid>
I above example I am expecting that the button is showing inside the templated groupbox. But all I see is a groupbox, the content presenter doesn’t show anything. I have no clue why.
What am I doing wrong?
>Solution :
You forgot to specify the TargetType of the ControlTemplate:
<ControlTemplate x:Key="GroupBoxTemplate" TargetType="ContentControl">
<GroupBox Header="ASD">
<ContentPresenter/>
</GroupBox>
</ControlTemplate>