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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:09:20+00:00 2026-06-17T10:09:20+00:00

I am trying to create a titled block UserControl in WPF/XAML, with the following

  • 0

I am trying to create a “titled block” UserControl in WPF/XAML, with the following behaviour:

  • The control itself is a Border containing a DockPanel. The DockPanel contains a top-aligned “title” TextBlock, and the rest of this DockPanel should be the “children widget area”.

The control declaration is like this:

<Border x:Name="LayoutRoot" Background="#4C000000" CornerRadius="10" Padding="10">
    <DockPanel>
        <TextBlock Text="Some Title" DockPanel.Dock="Top" />
    </DockPanel>
</Border>

And the intended usage is like this:

<Grid x:Name="LayoutRoot" Background="White">
    <local:Bloco Height="100" Width="100" Title="Other Title">
        <local:Bloco Title="Yet other title" />
    </local:Bloco>
</Grid>

To render something like this:

enter image description here

The actual current rendering is invalid, though. The problems are:

  • I don’t know (and didn’t found it via searching) how to make the control have a “children container” where I could add children via direct nesting in the XAML;
  • I don’t know how to bind a different title for each instance of the user control, be it via XAML attributes or bindings (preferrable), be it via code behind. Writing the code as above creates invalid xaml code, which is unsurprising since the “Title” attribute does not exist yet.

Thanks for reading!

  • 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-17T10:09:22+00:00Added an answer on June 17, 2026 at 10:09 am

    Generic usercontrol:

    XAML:

    <UserControl x:Class="WpfControlLibrary.GenericUserControl"
             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" xmlns:local="clr-namespace:WpfControlLibrary"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" x:Name="Control">
    <UserControl.Resources>
        <Style TargetType="{x:Type local:GenericUserControl}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:GenericUserControl}">
                        <Grid Background="{Binding Background, ElementName=Control}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="5"></RowDefinition>
                                <RowDefinition Height="20"></RowDefinition>
                                <RowDefinition Height="*"></RowDefinition>
                                <RowDefinition Height="5"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="5"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="5"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Title, ElementName=Control}"/>
                            <ContentPresenter Grid.Column="1" Grid.Row="2"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    

    Code behind:

    namespace WpfControlLibrary
    {
       public partial class GenericUserControl
       {
          public string Title
         {
            get { return (string)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
         }
    
         public static readonly DependencyProperty TitleProperty =
          DependencyProperty.Register("Title", typeof(string), typeof(GenericUserControl), new PropertyMetadata(string.Empty));
    
    public GenericUserControl()
         {
            InitializeComponent();
         }
       }
    }
    

    And than use the user control like this:

        <wpfControlLibrary:GenericUserControl Title="Other Title" Background="LightGray">
           <wpfControlLibrary:GenericUserControl Title="Yet Another Title" Background="Gray"/>
    </wpfControlLibrary:GenericUserControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Everything is there in the title itself. I am trying to create a custom
I am trying to create an app with some menus, an I am following
I'm trying to create a listview within a customdialog. listview contains a custom row
I'm trying to create a block for display content but I'm getting this error:
I'm currently trying to create a list of 5 blog titles of mine, where
As the title says, I'm trying to create a UIImage that will go inside
I'm trying the following query results = Tickets.order(created_at DESC).where({ (title =~ params[:title]) & (name
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
Ok so I am trying create a login script, here I am using PHP5

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.