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

  • Home
  • SEARCH
  • 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 4094578
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:45:45+00:00 2026-05-20T19:45:45+00:00

In my MainWindow I have an ObservableCollection which is shown in a Listbox per

  • 0

In my MainWindow I have an ObservableCollection which is shown in a Listbox per Binding.

If I update my Collection the modification is shown in the list.

This works:

public ObservableCollection<double> arr = new ObservableCollection<double>();

public MainWindow()
{
            arr.Add(1.1);
            arr.Add(2.2);
            testlist.DataContext = arr;
}

private void Button_Click(object sender, RoutedEventArgs e)
{
   arr[0] += 1.0;
}
<ListBox Name="testlist" ItemsSource="{Binding}"></ListBox>

This version works not:

public ObservableCollection<double> arr = new ObservableCollection<double>();

public MainWindow()
{
            arr.Add(1.1);
            arr.Add(2.2);
            testlist.DataContext = this;
}

private void Button_Click(object sender, RoutedEventArgs e)
{
   arr[0] += 1.0;
}
<ListBox Name="testlist" ItemsSource="{Binding Path=arr}"></ListBox>

Can you tell me why?
I would like to give this as the DataContext, because there are many other properties to show in my dialog and it would be nice if I wouldn’t have to set the DataContext for every individual control.

  • 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-20T19:45:46+00:00Added an answer on May 20, 2026 at 7:45 pm

    You need to expose your collection as a property, right now it’s a field. So make arr private again and add:

    public ObservableCollection<double> Arr {
        get {
            return this.arr;
        }
    }
    

    Then you will be able to bind like {Binding Path=Arr}, assuming this is the current DataContext.

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

Sidebar

Related Questions

I'm binding a ListBox to an ObservableCollection of items which have an Image property,
i have a window which is like this <Window x:Class=pharmacy_Concept.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350
I have a ListBox which displays the collection of MyObjects. The collection is in
This question looks like this one : Programmatically binding List to ListBox but as
I have a checkbox list of sports which is bound to an observable collection
Suppose I have this class: class MyClass(object): def uiFunc(self, MainWindow): self.attr1 = foo self.attr2
I have a listbox which has couple of items. When double clicked on each
I have a simple ViewModel like: public class MainViewModel { ObservableCollection<Project> _projects; public MainViewModel()
I've got a test collection setup as : ObservableCollection<Person> MyselectedPeople = new ObservableCollection<Person>(); public
In WPF app I have a ListView : <ListView Height=100 Width=434 x:Name=lvItems ItemsSource={Binding ElementName=MainWindow,

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.