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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:38:26+00:00 2026-05-26T11:38:26+00:00

I have a WPF listbox that houses a user control called JUC. This works

  • 0

I have a WPF listbox that houses a user control called JUC.

This works great and as I’m very new to WPF this already is very impressive. What I would like to do now is have different user controls in the list based upon a bound property.

Is this possible? If not, how else should I achieve this?

I’m using a list because I want to allow drop/drag ordering of the user controls, and there will be a variable number so seems to make sense – alternative approaches are welcome.

<ListBox x:Name="peopleListBox" 
    HorizontalAlignment="Stretch" 
    VerticalAlignment="Stretch"
    ItemContainerStyle="{StaticResource ListBoxItemStretch}"
    Foreground="Transparent" 
    BorderBrush="Transparent" 
    Background="Transparent" 
    Grid.ColumnSpan="2" SelectionChanged="peopleListBox_SelectionChanged">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid>
                     <my:JUC Margin="4"></my:JUC>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
  • 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-26T11:38:26+00:00Added an answer on May 26, 2026 at 11:38 am

    You can use DataTemplateSelector, in SelectTemplate() method you can check which DataTemplate to use for currently passed in item:

    In XAML:

    <!-- define templates in resources
         ChartDataTemplate is a ChartDataTemplate.xaml, the same for other
    -->
    <UserControl.Resources>
         <DataTemplate x:Key="ChartDataTemplate">
              <views:LineChartView />
         </DataTemplate>
    
         <DataTemplate x:Key="GridDataTemplate">
             <views:PieChartView />
         </DataTemplate>
    </UserControl.Resources>
    
    <!-- ListView Itemtemplate should point to template selector -->
    <ItemsControl.ItemTemplate>     
      <DataTemplate>
          <ContentPresenter 
                 ContentTemplateSelector = "{StaticResource MyTemplateSelector}">
    

    In Code behind:

     private sealed class MyTemplateSelector: DataTemplateSelector
     { 
    
        public override DataTemplate SelectTemplate(
                                          object item, 
                                          DependencyObject container)
        {
            // 1. case item to your object which is bound to each ListView item
            // 2. based on object type/state return correct DataTemplate
            // as this.Resources["ChartDataTemplate"] or
            // this.Resources["GridDataTemplate"] 
        }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to WPF. I have a ListBox that has its ItemSource set
I have a WPF listbox control that is declaratively bound to a textbox. The
I am just starting with WPF and I have this ListBox that displays an
I have a WPF listbox with custom items. Each item is a user control
I have a WPF ListBox that I would like to Enable multiple selection in
I have created styled a ListBox in WPF so that it is rendered as
I have a WPF application with ListBox that display list of items. Each item
I have a WPF Listbox filled with children that fire events. Now, I am
Lets say I have a WPF application that shows a ListBox with an ArrayList
I have a WPF Listbox defined in a DataTemplate that has its ItemsSource bound

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.