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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:03:26+00:00 2026-06-10T00:03:26+00:00

I am attempting to populate an ObservableCollection with the currently selected items in a

  • 0

I am attempting to populate an ObservableCollection with the currently selected items in a MultiSelectList. The method of selection involves a checkbox control, and I am unsure of how to get the selected items to populate the ObservableCollection. I have referenced two methods which perform a single selection of the MultiSelectList as well as a ‘select all’ option of the MultiSelectList.

To note, networkSelectList is an ObservableCollection in a custom Settings class.

MainPage.xaml

<toolkit:MultiselectList x:Name="connectionTypeMultiSelectList" HorizontalAlignment="Left" VerticalAlignment="Top" Tap="connectionTypeMultiSelectList_Tap">
    <toolkit:MultiselectList.ItemTemplate>
        <DataTemplate>

            <StackPanel Orientation="Horizontal"  Margin="12,0,0,0">
                <Image Source="{Binding Icon}" Width="35" Height="35" Margin="0"/>
                <TextBlock Text="{Binding Name}" TextAlignment="Center"  Margin="10"/>
            </StackPanel>

        </DataTemplate>
    </toolkit:MultiselectList.ItemTemplate>                            
</toolkit:MultiselectList>

MainPage.xaml.cs

/// <summary>
    /// method to Select All and UnSelect All checkboxes
    /// </summary>
    /// <param name="selected"></param>
    /// <param name="predicate"></param>
    private void SetCheckBoxesSelected(bool selected, Predicate<ConnectionItem> predicate)
    {
        if (networkTypeList == null)
        {
            return;
        }
        if (predicate == null)
        {
            predicate = (networkInfo) => true;
        }


        ItemContainerGenerator itemContainerGenerator = this.connectionTypeMultiSelectList.ItemContainerGenerator;


        foreach (ConnectionItem networkInfo in networkTypeList)
        {
            if (networkInfo != null && predicate(networkInfo))
            {
                DependencyObject visualItem = itemContainerGenerator.ContainerFromItem(networkInfo);
                MultiselectItem multiselectItem = visualItem as MultiselectItem;
                if (multiselectItem != null)
                {
                    multiselectItem.IsSelected = selected;

                    //add selected item to networkSelectionChecked  ??
                    //Settings.networkSelectionChecked.Value.Add(multiselectItem.Name.ToString());
                }
            }
        }
    }

    /// <summary>
    /// triggered on tap of any item in connectionTypeMultiSelectList
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void connectionTypeMultiSelectList_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        DependencyObject tappedElement = e.OriginalSource as UIElement;
        MultiselectItem tappedItem = this.FindParentOfType<MultiselectItem>(tappedElement);
        ConnectionItem selectedItem = null;
        if (tappedItem != null)
        {
            // DataContext contains reference to data item
            selectedItem = tappedItem.DataContext as ConnectionItem;
        }


        if (selectedItem != null)
        {
            MessageBox.Show(selectedItem.Name + "Tapped");

            //add selected item to networkSelectionChecked  ??
            //Settings.networkSelectionChecked.Value.Add(multiselectItem.Name.ToString());

        }
    }

    /// <summary>
    /// method to find out the element in VisualTree
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="element"></param>
    /// <returns></returns>
    private T FindParentOfType<T>(DependencyObject element) where T : DependencyObject
    {
        T result = null;
        DependencyObject currentElement = element;
        while (currentElement != null)
        {
            result = currentElement as T;
            if (result != null)
            {
                break;
            }
            currentElement = VisualTreeHelper.GetParent(currentElement);
        }
        return result;
    }

    void unselectAll_Click(object sender, EventArgs e)
    {
        this.SetCheckBoxesSelected(false, null);
        this.connectionTypeMultiSelectList.IsSelectionEnabled = false;
    }

    void selectAll_Click(object sender, EventArgs e)
    {
        this.SetCheckBoxesSelected(true, null);
    }

So basically I am trying to add each item that is selected to an ObservableCollection. I would like to accomplish this so that I will be able to create secondary tiles and update them by passing a querystring representing the selected checkboxes. How might I accomplish correctly adding the selected checkbox items to an ObservableCollection? Also in a similiar sense, how would I detect when an item is unselected and remove that item from the ObservableCollection? Additionally, is there a correct way to persist the selected items in the MultiSelectList so that this may be saved for future application launched or activations?

  • 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-10T00:03:28+00:00Added an answer on June 10, 2026 at 12:03 am

    You can get the selected items from the SelectedItems property.

    var selectedItems = new ObservableCollection<ConnectionItem>(connectionTypeMultiSelectList.SelectedItems.Count);
    foreach (var item in TextItemsList.SelectedItems)
    {
        var connectionItem = item as ConnectionItem;
        if (connectionItem == null) continue;
        selectedItems.Add(connectionItem );
    }
    

    The SelectionChanged event will let you know when an item is (un)selected.

    void MultiSelectListSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        foreach(var item in e.AddedItems)
        {
            // add to collection
        }
        foreach(var item in e.RemovedItems)
        {
            // remove from collection
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been attempting to populate a multiselectlist with the colors supported in WP7.1,
Attempting to get Spring internationalization working. I have used classpath:messages basename, created .properties files
I have an issue where I cannot seem to get the values to re-populate
I am attempting to populate a ScrollerViewer control with an arbitrary number of of
I'm currently using a WebBrowser control in a C# WinForms application, and attempting to
I am attempting to populate a dropdown based on the value selected in another
I am attempting to populate a list of links depeding on what checkbox options
I'm attempting to get Python to populate the lists with the closing prices of
While attempting to populate the items in a ListView following the outcome of a
I am attempting to populate A2:A13 with the months of the year. Obviously I

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.