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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:05:20+00:00 2026-05-10T20:05:20+00:00

I know how to create a custom user control in WPF but how can

  • 0

I know how to create a custom user control in WPF but how can I make it so that someone can provide an ItemTemplate?

I have a user control that is a mixture of several other WPF controls, one of them being a ListBox. I’d like to let the user of the control specify the content of the list box but I’m not sure how to pass that information through.

EDIT: The accepted answer works with the following correction:

<UserControl x:Class='WpfApplication6.MyControl'     xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'     xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'     xmlns:src='clr-namespace:WpfApplication6'>     <ListBox ItemTemplate='{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type src:MyControl}}, Path=ItemsSource}' /> </UserControl> 
  • 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. 2026-05-10T20:05:21+00:00Added an answer on May 10, 2026 at 8:05 pm

    You will want to add a DependencyProperty to your control. The xaml will look slightly different if you are deriving from UserControl or Control.

    public partial class MyControl : UserControl {     public MyControl()     {         InitializeComponent();     }      public static readonly DependencyProperty ItemTemplateProperty =         DependencyProperty.Register('ItemTemplate', typeof(DataTemplate), typeof(MyControl), new UIPropertyMetadata(null));     public DataTemplate ItemTemplate     {         get { return (DataTemplate) GetValue(ItemTemplateProperty); }         set { SetValue(ItemTemplateProperty, value); }     } } 

    Here is xaml for a UserControl.

    <UserControl x:Class='WpfApplication6.MyControl'     xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'     xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'     xmlns:src='clr-namespace:WpfApplication6'>     <ListBox ItemTemplate='{Binding ItemTemplate, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type src:MyControl}}}' /> </UserControl> 

    Here is xaml for a Control:

    <Style TargetType='{x:Type src:MyControl}'>     <Setter Property='Template'>         <Setter.Value>             <ControlTemplate TargetType='{x:Type src:MyControl}'>                 <Border Background='{TemplateBinding Background}'                         BorderBrush='{TemplateBinding BorderBrush}'                         BorderThickness='{TemplateBinding BorderThickness}'>                      <ListBox ItemTemplate='{TemplateBinding ItemTemplate}' />                 </Border>             </ControlTemplate>         </Setter.Value>     </Setter> </Style> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer They only come into play when the program crashes. PDB's… May 11, 2026 at 12:00 pm
  • added an answer From the docs: setcookie() defines a cookie to be sent… May 11, 2026 at 12:00 pm
  • added an answer you can try do next template < typename T >… May 11, 2026 at 12:00 pm

Related Questions

I know how to create a custom user control in WPF but how can
i kinda know how to create a Custom Web Part. But now i need
I know how to create a SEL at compile time using @selector(MyMethodName:) but what
I would like to know How to create a fps-game with SDL lib? Are
I know how to use tags in subversion. I create a tag every time
I know how to use JSON to create objects, but there doesn't seem to
I think I know how to create custom encrypted RSA keys, but how can
I'd like to know how one would create an application that starts in the
I know how to do this if I iterate through all of the characters
I know how to tell Castle Windsor to resolve a reference from a factory's

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.