Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

WPF ContentControl template won't show the content

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You forgot to specify the TargetType of the ControlTemplate:

<ControlTemplate x:Key="GroupBoxTemplate" TargetType="ContentControl">
    <GroupBox Header="ASD">
        <ContentPresenter/>
    </GroupBox>
</ControlTemplate>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading