Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8766101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:27:55+00:00 2026-06-13T16:27:55+00:00

Im trying to create a templated control that has a header, body, and footer

  • 0

Im trying to create a templated control that has a header, body, and footer content presenters.

So I created a class called BaseDockedSectionControl:

public class BaseDockedSectionControl:Control
{
    public BaseDockedSectionControl()
    {
        DefaultStyleKey = typeof(BaseDockedSectionControl);
    }

    public Grid Header
    {
        get { return (Grid)GetValue(HeaderProperty); }
        set { SetValue(HeaderProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Header.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty HeaderProperty =
        DependencyProperty.Register("Header", typeof(Grid), typeof(BaseDockedSectionControl), new PropertyMetadata(null));        

    public Grid Body
    {
        get { return (Grid)GetValue(BodyProperty); }
        set { SetValue(BodyProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Body.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty BodyProperty =
        DependencyProperty.Register("Body", typeof(Grid), typeof(BaseDockedSectionControl), new PropertyMetadata(null));



    public Grid Footer
    {
        get { return (Grid)GetValue(FooterProperty); }
        set { SetValue(FooterProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Footer.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty FooterProperty =
        DependencyProperty.Register("Footer", typeof(Grid), typeof(BaseDockedSectionControl), new PropertyMetadata(null));

          }

In App.XAML, I add a style to the Application.Resources:

<Style TargetType="local:BaseDockedSectionControl">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="local:BaseDockedSectionControl">
                        <Grid x:Name="RootElement">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="50"/>
                                <RowDefinition />
                                <RowDefinition Height="30"/>
                            </Grid.RowDefinitions>

                            <ContentPresenter Content="{TemplateBinding Header}"/>
                            <ContentPresenter Content="{TemplateBinding Body}"    Grid.Row="1"/>
                            <ContentPresenter Content="{TemplateBinding Footer}"  Grid.Row="2"/>                            
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

I then create a user control called Test.xaml, and enter the following xaml:

<UserControl x:Class="SilverlightIdeas.Test"
    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:SilverlightIdeas"
             xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <local:BaseDockedSectionControl>            
            <local:BaseDockedSectionControl.Header>
                <TextBlock Text="This is the header" />
            </local:BaseDockedSectionControl.Header>
        </local:BaseDockedSectionControl>

    </Grid>
</UserControl>

When I type in the TextBlock, the intellisense doesnt recognize it, and when I type it in, I get the message “Property Header does not support values of type ‘TextBlock’

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:27:57+00:00Added an answer on June 13, 2026 at 4:27 pm

    Two things fixed this.

    1. I made each of the dependency properties of type object

    2. Turns out that the problem was that the ContentPresenter seems to need to have an ending tag, rather than the self ending tag:

    becomes

    <ContentPresenter Content="{TemplateBinding Header}"></ContentPresenter>
    

    Once I did that, things started working correctly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a templated composite control that would work in a similar
I have been trying to create a templated class( Test2 ) that takes 2
I am trying to create a custom WPF control that has multiple UI elements
I'm trying to create a WPF window that has a single control and 2
I have been trying to find a good guide to create a templated control.
I'm trying to create my own templated List class as a practice excercise. I
I'm trying to create a templated control with Asp.Net MVC. By templated control, I
I'm trying to create a SplitButton control that uses a ContextMenu to display its
I am trying to create a User Control that, depending on the mode the
We're trying to create a ListBox which has a few items inside that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.