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

  • SEARCH
  • Home
  • 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 8021745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:04:37+00:00 2026-06-04T22:04:37+00:00

I have a user control with this code behind: /// <summary> /// The text

  • 0

I have a user control with this code behind:

/// <summary>
/// The text to use for the header.
/// </summary>
public UIElement HeaderText
{
    get { return (UIElement) GetValue(HeaderTextProperty); }
    set { SetValue(HeaderTextProperty, value); }
}

public static DependencyProperty HeaderTextProperty =
    DependencyProperty.Register("HeaderText",
                                typeof(UIElement),
                                typeof(Panel),
                                new PropertyMetadata(null, new PropertyChangedCallback(HeaderTextPropertyChanged)));

private static void HeaderTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    var control = d as Panel;
    if (control != null)
    {
        control.HeaderText = (UIElement) e.NewValue;
    }
}

And this XAML:

<TextBlock Text="{TemplateBinding local:CustomPanel.HeaderText}" />

And I’m trying to use the user control like this:

<controls:CustomPanel>
    <controls:CustomPanel.HeaderText>
        <TextBlock Text="Foo " />
        <TextBlock Text="{Binding Bar}" />
        <TextBlock Text=" baz." />
    </controls:CustomPanel.HeaderText>
</controls:CustomPanel>

However, what I get is blank/empty text.

I can get it to work if I change UIElement into string in code-behind, but I want to accept both string, TextBlock and practically any UIElement that makes sense for text.

How can I achieve this?

  • 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-04T22:04:40+00:00Added an answer on June 4, 2026 at 10:04 pm

    Don’t use a TextBlock in your control but a ContentPresenter (and bind the Content), it can host anything. Make the property type object and change the name to Header for consistency.

    (As a side-note: Usually you have additional properties that go along with the Header, namely a HeaderTemplate and a HeaderTemplateSelector. If the ContentPresenter is in a template you can make it bind to all three properties by setting the ContentSource to "Header")

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

Sidebar

Related Questions

I have a simple user control with this code: <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Pager.ascx.cs"
My current situation: I have a user control A.ascx with code behind A.ascx.cs and
In a normal user control, we have .cs.ascx (code-behind) to assign the namespace we
I have this user control: <%@ Control Language=C# AutoEventWireup=true CodeBehind=cite.ascx.cs Inherits=cite %> with behind
I have a user control in XAML code (a data grid) with this databind
I have this code: Control ctrl = Page.LoadControl(~/UserControls/ReportControl.ascx); IReport rpt = (IReport)ctrl; rpt.LoadData(); Panel.Controls.Add(ctrl);
I have a user control like this: <UserControl x:Class=MyApp.UserControls.MyContextMenu xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:d=http://schemas.microsoft.com/expression/blend/2008 mc:Ignorable=d
I have a user control let say UC1 . This user control have viewmodel
I have a custom user control on my windows forms. This control has a
I have MyContainer User Control with Grid inside. Each cell of this Grid contains

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.