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

The Archive Base Latest Questions

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

i dont really understand why and what happens in the background, so please help

  • 0

i dont really understand why and what happens in the background, so please help me with it.
I have a simple ListView:

<ListView Height="100" HorizontalAlignment="Left" Margin="67,84,0,0" ItemsSource="
{Binding Path=ListBinding}" Name="listView1" VerticalAlignment="Top" Width="351" />

and a Button:

<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="162,41,0,0"
 Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />

And I set the datacontext to my “viewmodel” class:

        InitializeComponent();

        this.DataContext = new VM1();

now, if i initialise the obscollection in the VM1’s constructor, the binding works, when i populate the ListBinding with the button1_click function:

private void button1_Click(object sender, RoutedEventArgs e)
{
    (this.DataContext as VM1).Do();
}

public VM1()
{
   ListBinding = new ObservableCollection<string>();
}

public void Do()
{
    ListBinding.Add("VM1 works 1");
    ListBinding.Add("VM1 works 2");
}

But if i initialize it in the Do() function, it doesnt:

public VM1()
{ }

public void Do()
{
   ListBinding = new ObservableCollection<string>();
   ListBinding.Add("VM1 NOT works 1");
   ListBinding.Add("VM1 NOT works 2");
}

I guess the answer to this might be a one liner, and i wanna understand the “why”.
thanks!

  • 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-07T10:31:15+00:00Added an answer on June 7, 2026 at 10:31 am

    You did not list the code for the ListBinding property.
    The property setter must call NotifyOfPropertyChange so the binding will get updated.
    ObservableCollection automatically updates with the CONTENTS of the list change, not the entire list object.

    Hope that helps.

    Edit: here is the code for the property:

        private ObservableCollection<string> _listBinding // backing field
        public ObservableCollection<string> ListBinding
        {
            get { return _listBinding; }
            set {
                _listBinding = value;
                NotifyOfPropertyChange("ListBinding"); // let the bindings update
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't understand why happens this. I have a simple application in WPF. This
I dont really understand whats going on and cant see the difference: I'm downloaded
I dont really understand why this is not working, I am being returned to
I am currently learning bash programming and dont really understand why the passing argument
I don't really understand what happens if I check out an old commit, do
Guys, please help me with the following problem. I have encountered the famous cannot
I understand why it does that but I don't really have any idea of
i really dont understand what happen here, its works on most of servers but
Im getting Exception in thread AWT-EventQueue-0 java.lang.ArrayIndexOutOfBoundsException:0 and I really dont understand why. I
I don't really understand when session is created and per what entity it is

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.