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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:24:35+00:00 2026-05-15T15:24:35+00:00

I am not quite grokking the difference between ItemsSource and DataContext. Can someone explain

  • 0

I am not quite grokking the difference between ItemsSource and DataContext. Can someone explain it and back it up with examples? When would I use one or the other.

I am reading the docs and it says that I can bind using DataContext, but I throw an ObservableCollection at it and nothing shows up in the list. If I throw the same collection at the ItemsSource, it works fine.

  • 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-15T15:24:35+00:00Added an answer on May 15, 2026 at 3:24 pm

    Controls (including the ListBox) don’t do anything with the value of DataContext at all. Its purpose is to provide a context for data bindings.

    Lets assume you have a ListBox “myList” and a MyData “myData”. The MyData type has a property “People” of type ObservableCollection<Person> and in turn the Person type has the string properties “Forename” and “Surname”.

    All of the following are equivalent:-

     myList.ItemsSource = myData.People;
    

    or

     myList.DataContext = myData;
     myList.SetBinding(ItemsControl.ItemsSourceProperty, new Binding("People"));
    

    or

     myList.DataContext = myData.People;
     myList.SetBinding(ItemsControl.ItemsSourceProperty, new Binding());
    

    Typically though bindings are configured in Xaml and the DataContext of the LayoutRoot is assigned the data object:-

     LayoutRoot.DataContext = myData;
    

    you might have the following Xaml:-

     <Grid x:Name="LayoutRoot">
       <ListBox x:Name="myList" ItemsSource="{Binding People}">
         <ListBox.ItemTemplate>
           <DataTemplate>
             <StackPanel Orientation="Horizontal">
               <TextBlock Text="{Binding Forename}" Margin="2" />
               <TextBlock Text="{Binding Surname}" Margin="2" />
             </StackPanel>
           </DataTemplate>
         </ListBox.ItemTemplate>
       </ListBox>
     </Grid>
    

    You’ll note a couple of things here. The DataContext of “myList” is not assigned at all. In this case the control’s ancestor tree is walked until an ancestor is found that does have a value assigned to the DataContext property.

    Also each ListBoxItem dynamically generated for each Person instance has that Person instance assigned as its DataContext which is how the Forename and Surname bindings manage to work.

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

Sidebar

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.