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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:34:36+00:00 2026-06-05T05:34:36+00:00

I have a listbox that is bound to an observablecollection. The observable collection contains

  • 0

I have a listbox that is bound to an observablecollection. The observable collection contains a list of objects, each with it’s own observablecollection. What i want is to click an item in the first listbox and have it’s list of things displayed in the second listbox. Can I do this in pure WPF?

  • 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-05T05:34:38+00:00Added an answer on June 5, 2026 at 5:34 am

    Just bind the ItemsSource of the second listbox to the SelectedItem of the first list box.

    Edit: here is some code.

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            TestItems = new ObservableCollection<Test>();
            InitializeComponent();
    
            for (int i = 0; i < 5; i++)
                TestItems.Add(InitTest(i));
        }
    
        public ObservableCollection<Test> TestItems { get; set; }
    
        private Test InitTest(int index)
        {
            Test test = new Test();
            test.Name  = "Test" + index.ToString();
            test.Test2Items =  new ObservableCollection<Test2>();
    
            for (int i = 0; i <= index; i++)
            {
                Test2 test2 = new Test2();
                test2.Label = test.Name + "_label" + i.ToString();
                test.Test2Items.Add(test2);
            }
            return test;
        }
    }
    
    public class Test
    {
        public string Name { get; set; }
        public ObservableCollection<Test2> Test2Items { get; set; }
    
        public override string ToString()
        {
            return Name;
        }
    }
    
    public class Test2
    {
        public string Label { get; set; }
        public override string ToString()
        {
            return Label;
        }
    }
    

    Xaml

     <Window x:Class="WpfApplication1.MainWindow"
            x:Name="MyWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="WPF Example" Height="300" Width="400">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <ListBox x:Name="ListBox1" Grid.Column="0" ItemsSource="{Binding TestItems, ElementName=MyWindow}" />
            <ListBox Grid.Column="1" ItemsSource="{Binding SelectedItem.Test2Items, ElementName=ListBox1}" />
        </Grid>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListBox that is bound to a list of Persons. I want
Say I have a ListBox that is bound to an observable collection on my
I have a ListBox, that's bound to an ObservableCollection . Each ListBoxItem is displayed
I have a ObservableCollection that's bound to a ListBox in WPF. I want the
I have a ListBox bound to an ObservableCollection. The items in the collection each
I currently have a listbox that has its selected item bound to a property
I have a ListBox in Silverlight that has a list of items inside. Each
I have a listbox item template that contains visual states. I have DisplayStateBehaviors that
I have an observable collection bound to a listbox in WPF. One of the
I have ObservableCollection<Foo> that is bound to an ItemsControl (basically displaying a list). Foo

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.