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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:45:42+00:00 2026-05-15T00:45:42+00:00

As an exercise to learn wpf and understand how binding works I have an

  • 0

As an exercise to learn wpf and understand how binding works I have an example that works.However when I try to load on demand I fail miserably.

I basically have 3 classes Country-City-Hotels

If I load ALL in one go it all works if I load on demand it fails miserably.
What Am I doing wrong?

Works

        <Window x:Class="MasterDetailCollectionViewSource.CountryCityHotelWindow"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                Title="CountryCityHotelWindow" Height="300" Width="450">
            <Window.Resources>
                <CollectionViewSource Source="{Binding}" x:Key="cvsCountryList"/>
                <CollectionViewSource Source="{Binding Source={StaticResource cvsCountryList},Path=Cities}" x:Key="cvsCityList"/>
                <CollectionViewSource Source="{Binding Source={StaticResource cvsCityList},Path=Hotels}" x:Key="cvsHotelList"/>
            </Window.Resources>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <TextBlock Grid.Column="0" Grid.Row="0" Text="Countries"/>
                <TextBlock Grid.Column="1" Grid.Row="0" Text="Cities"/>
                <TextBlock Grid.Column="2" Grid.Row="0" Text="Hotels"/>

                <ListBox Grid.Column="0" Grid.Row="1" Name="lstCountries" ItemsSource="{Binding Source={StaticResource cvsCountryList}}" DisplayMemberPath="Name" SelectionChanged="OnSelectionChanged"/>
                <ListBox Grid.Column="1" Grid.Row="1" Name="lstCities" ItemsSource="{Binding Source={StaticResource cvsCityList}}" DisplayMemberPath="Name" SelectionChanged="OnSelectionChanged"/>
                <ListBox Grid.Column="2" Grid.Row="1" Name="lstHotels" ItemsSource="{Binding Source={StaticResource cvsHotelList}}" DisplayMemberPath="Name" SelectionChanged="OnSelectionChanged"/>
            </Grid>
        </Window>

DOES NOT WORK

Xaml is the same as above, however I have added the following that fetches stuff on demand.
It loads the countries only as opposed to the other one where it Loads everything at once and not code behind is necessary.

    public CountryCityHotelWindow()
    {
        InitializeComponent();

        //Load only country Initially
        lstCountries.ItemsSource=Repository.GetCountries();
        DataContext = lstCountries;
    }

    private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var lstBox = (ListBox)e.OriginalSource;
        switch (lstBox.Name)
        {
            case "lstCountries":
                var country = lstBox.SelectedItem as Country;
                if (country == null) return;
                lstCities.ItemsSource = Repository.GetCities(country.Name);
                break;
            case "lstCities":
                var city = lstBox.SelectedItem as City;
                if (city == null) return;
                lstHotels.ItemsSource = Repository.GetHotels(city.Name);
                break;
            case "lstHotels":
                break;
        }
    }

What Am I doing Wrong?
Thanks

  • 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-15T00:45:42+00:00Added an answer on May 15, 2026 at 12:45 am

    Just realised something that made it all work!
    I was missing

    IsSynchronizedWithCurrentItem=”True”

    Now this works as espected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn scheme via SICP. Exercise 1.3 reads as follow: Define a
I am new to functional programming, and now learn Haskell. As an exercise I
As a programming exercise, I've written a Ruby snippet that creates a class, instantiates
I'm writing a real NumericUpDown/Spinner control as an exercise to learn custom control authoring.
I'm rewriting a Web Forms application as an exercise to learn some MVC skills.
I have a couple of Python functions that I use to make game development
I have a small project which I started in bazaar, as an exercise to
I recently decided to try to learn some bash scripting and as a fun
I am reading through a Learn C book right now and have come across
I thought that I was really starting to understand how pointers work, and then

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.