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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:32:07+00:00 2026-06-04T02:32:07+00:00

Is that even possible? I have two ObservableCollections. I want to bind and populate

  • 0

Is that even possible? I have two ObservableCollections. I want to bind and populate a listbox with one of them. For example let’s say that we have 2 buttons – one for Twitter and one for Facebook. Clicking on a Facebook button it will populate listbox with friend’s names from facebook observable collection and it will bind it. Clicking on Twitter it will populate listbox with Twitter followers and populate listbox and bind it.

How to choose which collection will be populated in listbox?

  • 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-04T02:32:08+00:00Added an answer on June 4, 2026 at 2:32 am

    I would just use one observable collection and fill based on the users choice. You could also fill it with the names from both sources and have a filter to filter out one or the other (apparently you need a wrapper object where you can indicate whether the name is a facebook friend or twitter follower).

    Edit: Here is some quick code example of how you can do it:

    public interface ISocialContact
    {
        string Name { get; }
    }
    
    public class FacebookContact : ISocialContact
    {
        public string Name { get; set; }
        public string FacebookPage { get; set; }
    }
    
    public class TwitterContact : ISocialContact
    {
        public string Name { get; set; }
        public string TwitterAccount { get; set; }
    }
    

    Then in your data context:

    public ObservableCollection<ISocialContact> Contacts { get; set; }
    
    ...
    
    Contacts = new ObservableCollection<ISocialContact> {
                        new FacebookContact { Name = "Face", FacebookPage = "book" },
                        new TwitterContact { Name = "Twit", TwitterAccount = "ter" } 
               };
    

    And in your xaml:

    <Grid>
        <Grid.Resources>
            <DataTemplate DataType="{x:Type local:FacebookContact}">
                <TextBlock Text="{Binding FacebookPage}"/>
            </DataTemplate>
            <DataTemplate DataType="{x:Type local:TwitterContact}">
                <TextBlock Text="{Binding TwitterAccount}"/>
            </DataTemplate>
        </Grid.Resources>
        <ListBox ItemsSource="{Binding Contacts}" Width="100" Height="100"/>
    </Grid>
    

    This will apply the appropriate template to each object in your collection. So you can have collection with just facebook contacts or just twitter contacts or mixed.

    Also note: You do not need the common interface. It will also work if you just make your ObservableCollection of type object. But given that they are being displayed by the same app in the same list box indicates that you can find some kind of common base and either can create a comon interface or base class.

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

Sidebar

Related Questions

Mathematically I suppose it's possible that even two random GUIDs generated using the built
I'd like to have URLs that are even shorter than /{Controller}/{Action}/{Id}. For example, I'd
Let's say I have a function that takes a string. That string contains the
in my db I have two tables that are related. Lets call them Job
I'm curious if it's possible to have more than two iPads/iPhones connected to one
I have two functions and i want to make it like one. function 1
Is it possible that even if I'm using a class from a swc it
How is it possible that following code even compiles? As far as I can
One would expect that even though strings are immutable, value-equality and reference-equality would not
I'm using the i18n feature of Django. I have noticed that even though 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.