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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:42:46+00:00 2026-05-31T20:42:46+00:00

I am currently implementing the application that displays hierarchy using ListBoxes (please do not

  • 0

I am currently implementing the application that displays hierarchy using ListBoxes (please do not suggest using TreeView, ListBoxes are needed).

It looks like that in the article: WPF’s CollectionViewSource (with source code).

enter image description here

Classes:

public class Mountains : ObservableCollection<Mountain>
{
    public ObservableCollection<Lift> Lifts { get; }

    public string Name { get; }
}

public class Lift
{
    public ObservableCollection<string> Runs { get; }
}

The example uses CollectionViewSource instances (see XAML) to simplify the design.
An instance of Mountains class is the DataContext for the window.


The problem is: I would like that the Mountains class to have SelectedRun property and it should be set to currently selected run.

public class Mountains : ObservableCollection<Mountain>
{
    public ObservableCollection<Lift> Lifts { get; }

    public string Name { get; }

    public string SelectedRun { get; set; }
}

Maybe I’ve missed something basic principle, but how can I achieve this?

  • 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-31T20:42:47+00:00Added an answer on May 31, 2026 at 8:42 pm

    You may want to read about the use of ‘/’ in bindings. See the section ‘current item pointers’ on this MSDN article.

    Here’s my solution:

    Xaml

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
    
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
    
        <TextBlock Margin="5" Grid.Row="0" Grid.Column="0" Text="Mountains"/>
        <TextBlock Margin="5" Grid.Row="0" Grid.Column="1" Text="Lifts"/>
        <TextBlock Margin="5" Grid.Row="0" Grid.Column="2" Text="Runs"/>
    
        <ListBox Grid.Row="1" Grid.Column="0" Margin="5" 
                 ItemsSource="{Binding Mountains}" DisplayMemberPath="Name" 
                 IsSynchronizedWithCurrentItem="True" />
    
        <ListBox Grid.Row="1" Grid.Column="1" Margin="5" 
                 ItemsSource="{Binding Mountains/Lifts}" DisplayMemberPath="Name" 
                 IsSynchronizedWithCurrentItem="True"/>
    
        <ListBox Grid.Row="1" Grid.Column="2" Margin="5" 
                 ItemsSource="{Binding Mountains/Lifts/Runs}" 
                 IsSynchronizedWithCurrentItem="True" 
                 SelectedItem="{Binding SelectedRun}"/>
    </Grid>
    

    C# (note, you don’t need to implement INotifyPropertyChanged unless the properties will be changed and not just selected)

    public class MountainsViewModel
    {
        public MountainsViewModel()
        {
            Mountains = new ObservableCollection<Mountain>
                            {
                                new Mountain
                                    {
                                        Name = "Whistler",
                                        Lifts = new ObservableCollection<Lift>
                                                    {
                                                        new Lift
                                                            {
                                                                Name = "Big Red",
                                                                Runs = new ObservableCollection<string>
                                                                           {
                                                                               "Headwall",
                                                                               "Fisheye",
                                                                               "Jimmy's"
                                                                           }
                                                            },
                                                        new Lift
                                                            {
                                                                Name = "Garbanzo",
                                                                Runs = new ObservableCollection<string>
                                                                           {
                                                                               "Headwall1",
                                                                               "Fisheye1",
                                                                               "Jimmy's1"
                                                                           }
                                                            },
                                                        new Lift {Name = "Orange"},
                                                    }
    
                                    },
                                new Mountain
                                    {
                                        Name = "Stevens",
                                        Lifts = new ObservableCollection<Lift>
                                                    {
                                                        new Lift {Name = "One"},
                                                        new Lift {Name = "Two"},
                                                        new Lift {Name = "Three"},
                                                    }
    
                                    },
                                new Mountain {Name = "Crystal"},
                            };
        }
    
        public string Name { get; set; }
        private string _selectedRun;
        public string SelectedRun
        {
            get { return _selectedRun; }
            set
            {
                Debug.WriteLine(value);
                _selectedRun = value;
            }
        }
    
        public ObservableCollection<Mountain> Mountains { get; set; }
    }
    
    public class Mountain
    {
        public string Name { get; set; }
    
        public ObservableCollection<Lift> Lifts { get; set; }
    }
    
    public class Lift
    {
        public string Name { get; set; }
    
        public ObservableCollection<string> Runs { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently implementing a client application that POST's a file over HTTP and have
I'm currently implementing a histogram that will show a very large scale data using
I am currently working on a application that will be implementing user customizable widgets
I am currently implementing Quartz.net in a simple application that should execute a piece
I'm currently implementing a Monotouch application that will eventually be ported to Monodroid. The
I'm currently on my way to write a web application implementing the MVC and
Currently I'm implementing a Persistant Storage Object for my Blackberry Application. It contains a
I'm currently implementing a JavaScript library that keeps track of the history of changes
I'm currently implementing a .NET wrapper for a Java library by using JNI to
I am currently implementing a repository in my MVC 3 application. All the repository

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.