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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:38:15+00:00 2026-05-31T21:38:15+00:00

I have 2 listboxes in my XAML and both of them are multi select.

  • 0

I have 2 listboxes in my XAML and both of them are multi select. I have synchronized the selectedItems of the listboxes using Samuel Jack’s solution.

<ListBox x:Name="lbOrg" HorizontalAlignment="Left" Grid.Column="1" Grid.Row="0"
 Margin="15,3,5,3" Width="200" Height="120" ItemsSource="{Binding AvailableOrg}" 
LSync:MultiSelectorBehaviours.SynchronizedSelectedItems="{Binding SelectedOrg}" 
SelectionMode="Extended" DisplayMemberPath="OrgShortName"/>


<ListBox x:Name="lbSite" HorizontalAlignment="Left" Grid.Column="3" Grid.Row="0" 
Margin="15,3,5,3" Width="200" Height="120" ItemsSource="{Binding AvailableSites}"     
LSync:MultiSelectorBehaviours.SynchronizedSelectedItems="{Binding SelectedSites}"  
SelectionMode="Extended" DisplayMemberPath="SiteShortName"/>

The lbSite needs to be populated depending on the values selected in lbOrg. So, in order to let the ViewModel know about the selection changed for lbOrg, I am handling the selection changed event for the Selected Items list for lbOrg and calling a method to populate the values for lbSite.

    public void Load()
    {            
        _selectedOrg = new ObservableCollection<object>();
        _selectedSites = new ObservableCollection<object>();            

        _selectedOrg.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(_selectedOrg_CollectionChanged);            
    }

    private void _selectedOrg_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {            
        if (AvailableSites != null)
            AvailableSites.Clear();            

        if(SelectedOrg != null && SelectedOrg.Count > 0)
        {
            foreach (object org in SelectedOrg)
            {
                if (AvailableSites == null || AvailableSites.Count == 0)
                    AvailableSites = WebClient.getSitesForOrg(((OrganizationModel)org).OrgId);
                else
                {
                    ObservableCollection<object> tempSiteList = WebClient.getSitesForOrg(((OrganizationModel)org).OrgId);
                    foreach (object site in tempSiteList)
                    {
                        AvailableSites.Add(site);
                    }
                }
            }
        }
    }

And I have defined the properties as:

public ObservableCollection<object> SelectedOrg
    {
        get
        {
            return _selectedOrg;
        }
        set
        {
            _selectedOrg = value;                
            OnPropertyChanged("SelectedOrg");
        }
    }

public ObservableCollection<object> AvailableSites
    {
        get
        {
            return _availableSites;
        }
        set
        {
            _availableSites = value;
            OnPropertyChanged("AvailableSite");
        }
    }

My ViewModelBase implements the INotifyPropertyChanged. Also, the properties are defined as ObservableCollection where the object has been cast from seperate custom classes in both the properties.

I guess this should have been easy, but due to some strange reason, the listbox is not getting notified about the property getting changed and hence no change to the source is getting reflected on the view. I have bound an eventHandler with the Selection changed event of the lbOrg in the code behind to check if the Itemssource for lbSite gets updated, but it doesn’t though the AvailableSites property had the values required.

Any help here would be greatly appreciated.

  • 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-31T21:38:17+00:00Added an answer on May 31, 2026 at 9:38 pm

    You’ve missed an “s”. 🙂

    OnPropertyChanged("AvailableSite");
    

    should be

    OnPropertyChanged("AvailableSites");
    

    I have some code in my ViewModelBase that checks the string when in debug mode, it’s quite helpful for catching such errors:

    [Conditional("DEBUG")]
    private void CheckPropertyNameIsValid(string propertyName)
    {
        // INotifyPropertyChanged notifies via strings, so use 
        // this helper to check that the string is accurate in debug builds.
        if (TypeDescriptor.GetProperties(this)[propertyName] == null)
            throw new Exception("Invalid property name: " + propertyName);
    }
    

    There are also various elegant solutions knocking around for removing the reliance on magic strings altogether for INotifyPropertyChanged, but I’ve not got around to using any of these yet.

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

Sidebar

Related Questions

I have a listbox defined in XAML as: <ListBox x:Name=directoryList MinHeight=100 Grid.Row=0 ItemsSource={Binding Path=SelectedDirectories}/>
I have a ListBox written in xaml : <ListBox Margin=0 x:Name=ListBox_Main Grid.Row=1 VerticalAlignment=Top FontSize=24
So, I have this ListBox written in XAML: <ListBox Margin=0 x:Name=ListBox_Main Grid.Row=1 VerticalAlignment=Top FontSize=24
In my XAML file, I have a ListBox declared like this : <ListBox x:Name=lstDeck
i have customized ListBox declared in XAML: <ListBox x:Name=uicMDSQonfServer> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation=Horizontal Margin=0,5,0,5>
I have a ListBox with the following XAML: <ListBox.ItemTemplate> <DataTemplate> <Grid Name=listItemGrid> <Grid.ColumnDefinitions> <ColumnDefinition
I have a xaml navigation page with 5 listboxes (Silverlight 3). Four of the
In xaml, I have a listbox with a grid in it with 1 row
I have a ListBox which uses a DataTemplate to render databound items. The XAML
So I have this Xaml inside a ListBox Item Template: <ListBox.ItemTemplate> <DataTemplate> <Grid Height=22

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.