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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:07:31+00:00 2026-06-07T20:07:31+00:00

Is there a way to determine the associated ObservableCollection programmatically from a ListBox? I

  • 0

Is there a way to determine the associated ObservableCollection programmatically from a ListBox?

I bound the ItemsSource to a ListBox in my XAML and when a user selects an item from within it, I want the program to find not only which ListBox the item came from (which I’ve managed to do) but also get the ObservableCollection associated with it.

I thought that by using sourceContainer.ItemsSource.ToString() (where sourceContainer is the programmatically-found ListBox) I would be able to determine the DataBound ObservableCollection behind it. However, this isn’t the case. What am I missing?

Thanks!

Edit: Here’s some code pertaining to the creation of the ObservableCollections and how I’m determining which box is selected. (I know it probably isn’t the best way, I’m still learning…)

First off, the XAML (each ListBox has this line for general binding):

ItemsSource="{Binding Path=ListOneItems}"

Now the code for creating the ObservableCollections:

    private ObservableCollection<DataItem> listOneItems;

    public ObservableCollection<DataItem> ListOneItems
    {
        get
        {
            if (listOneItems == null)
            {
                listOneItems = new ObservableCollection<DataItem>();
            }
            return listOneItems;
        }
    }

Here’s where the program determines the parent of the selected item:

//Finds the name of the container that holds the selected SLBI (similar to finding the initial touched object)
FrameworkElement determineSource = e.OriginalSource as FrameworkElement;
SurfaceListBox sourceContainer = null;

while (sourceContainer == null && determineSource != null)
{
    if ((sourceContainer = determineSource as SurfaceListBox) == null)
    {
        determineSource = VisualTreeHelper.GetParent(determineSource) as FrameworkElement;
    }
}

//Name of the parent container
strParentContainer = sourceContainer.Name;

//Name of the ObservableCollection associated with parent container?

If anything else is needed, let me know.

  • 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-07T20:07:34+00:00Added an answer on June 7, 2026 at 8:07 pm

    If you’ve bound directly to a property that is an ObservableCollection<T>, you should be able to do this:

    var col = (ObservableCollection<MyClass>)sourceContainer.ItemsSource;
    

    If that’s not the case, you’ll need to post the relevant XAML and code.

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

Sidebar

Related Questions

Is there a way to determine programmatically, using Python, which web page is currently
Is there a way to determine programmatically, using Python, which web page is currently
Is there a way to determine if an item, in my case the webbrowser,
Is there any way to determine the local culture of a PC (such as
Is there any way to determine if the mouse scrolls up or down using
Is there a way to determine Internet Explorer Cookie Settings (that is, whether cookies
Is there a way to determine if a MATCH query sent to an fts3
Is there a way to determine what kind of data plan a device has
Is there a way to determine which ClassLoader loads a specific class? Or more
Is there any way to determine a page numer (in paged list), that contains

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.