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 337913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:22:49+00:00 2026-05-12T10:22:49+00:00

I am new to using the ControlTemplate . I am writing my first control

  • 0

I am new to using the ControlTemplate. I am writing my first control but I am having (what seems to me) a very strange issue.

Any dependency properties that I make TemplateBinding to work, but any properties from the .NET framework objects i.e. the Content property of a ContentControl or the Items property of an ItemsControl does not get populated at runtime.

I am sure I am missing something… Just what it is I dont know…

An example of the code is below:

The class is very simple at the moment:

public class Title : ContentControl
{
}

And the Template is:

<Style TargetType="{x:Type UI:Title}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type UI:Title}">
                <TextBlock Text="{TemplateBinding Content}" />
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

The base ContentControl class is the .NET class located in the System.Windows.Controls.Control namespace.

Thanks,

Adam

  • 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-05-12T10:22:49+00:00Added an answer on May 12, 2026 at 10:22 am

    I believe if you’d like to override where the Content is placed you can do that using a ContentPresenter.

    <Style TargetType="{x:Type UI:Title}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type UI:Title}">
                    <Label>
                        <ContentPresenter />
                    </Label>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    Note I’ve also changed from a TextBlock to a Label as I believe the TextBlock.Text property will not accept everything from ContentControl.Content. Here is an example I put together that works as intended:

    <Window x:Class="ContentControlTest.Window1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:ContentControlTest"
            Title="Window1" Height="300" Width="300">
        <Window.Resources>
            <Style TargetType="{x:Type local:Title}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type local:Title}">
                            <Button>
                                <ContentPresenter />
                            </Button>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Window.Resources>
        <local:Title>
            <TextBlock Text="Happy Days!" />
        </local:Title>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe this is a very silly question but I'm new using django. I have
I'm new using the excellent stuff of css twitter bootstrap and having a problem,
I'm new using Yii framework. I show a list a checkbox. But it's not
I'm using new style classes in Python 2.6 and am having trouble with __getattr__
Very new to using Raphael.js I'm looking at the tutorials and I am able
I am new to using Jade -- and it's awesome so far. But one
Relatively new to C# and MVVM, but I'm making a WP7 app using the
I still very new using Subversion. Is it possible to have a working copy
I still new using Asp.net with vb.net Protected Sub login_Click(ByVal sender As Object, ByVal
New at using admob within Android. Is it possible to show ads with certain

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.