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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:08:40+00:00 2026-06-05T16:08:40+00:00

I have defined following control template for my custom control. <ControlTemplate TargetType={x:Type local:CustomControl}> <Grid

  • 0

I have defined following control template for my custom control.

<ControlTemplate TargetType="{x:Type local:CustomControl}">
    <Grid x:Name="MainGrid">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <local:CustomPanel x:Name="MyCustomPanel" Grid.Column="0" />
        <ScrollBar Grid.Column="1" Width="20" />
    </Grid>
</ControlTemplate>

Here the CustomPanel derives form Panel class. Now I cannot add the items to my CustomControl directly like this

<local:CustomControl x:Name="CControl" Grid.Row="1">
    <Button/>
    <Button/>
    <Button/>
</local:CustomControl>

What can I do for adding the items to my custom control directly from XAML?

  • 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-05T16:08:41+00:00Added an answer on June 5, 2026 at 4:08 pm

    Here is a sample control that allows you to directly add content in the way that you’re after.

    The lines of interest here are the attribute on top of the MyCustomControl class, this tells the XAML editor which property any directly added content should be placed in.

    In the XAML code the important line is the ItemsControl that’s bound to the Items property, this actually displays each item.

    C#

    [ContentProperty("Items")]
    public class MyCustomControl : Control
    {
        public ObservableCollection<Object> Items
        {
            get { return (ObservableCollection<Object>)GetValue(ItemsProperty); }
            set { SetValue(ItemsProperty, value); }
        }
    
        public static readonly DependencyProperty ItemsProperty =
            DependencyProperty.Register("Items", typeof(ObservableCollection<Object>), typeof(MyCustomControl), new UIPropertyMetadata(new ObservableCollection<object>()));        
    }
    

    XAML

    <Style TargetType="{x:Type local:MyCustomControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:MyCustomControl}">
                    <ItemsControl ItemsSource="{TemplateBinding Items}"  />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <local:MyCustomControl>
        <Button />
        <Button />
    </local:MyCustomControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following defined in xaml: <Setter Property=Template> <Setter.Value> <ControlTemplate> <Popup Visibility=Visible> <TextBlock
I have the following Silverlight control defined: <object id=objImageViewer data=data:application/x-silverlight-2, type=application/x-silverlight-2 width=100% height=500px> <param
I have the following style defined... <!-- Blue Button --> <Style x:Key=BlueButton TargetType={x:Type Button}>
If I have defined the following types: type category = Noun | Verb |
I have 4 popups, defined like this: <Popup x:Name=MyPopup1 IsOpen=True Margin=0,10,0,0 Grid.Row=0 > <Popup.Child>
I have the following custom defined Button defined in my App.xaml file. <Style x:Key=DispatchListCallButton
I have the following struct defined in a user control: public struct ColumnData {
I created style for a toggle button, defined below: <Style TargetType={x:Type ToggleButton}> <Setter Property=Template>
I have defined following in a ResourceDictionary: <DockPanel x:Key=errorDisplay LastChildFill=False> <Border Background=Red DockPanel.Dock=Top> <TextBlock
In my .htaccess file I have defined following rule, RewriteRule t/([^.]+)/$ /videos/tag.php?tag=$1 [QSA] 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.