title: Element added to ObservableCollection in ViewModel not displayed
body: <p>Quite a newbie in the world of WPF. I've been hurting my eyes for several days now, looking for a solution, but didn't manage to make it right.</p>
  
  <p><strong>What I'm trying to achieve :</strong></p>
  
  <ul>
  <li>Create an ObservableCollection in a view model class</li>
  <li>Bind the data inside the .xaml file</li>
  <li>Create a "Add" button from private void Button_Click in the MainWindow.xaml.cs <em>(I'll create commands later - I just need to take it step by step and keep it simple to understand the process.)</em></li>
  </ul>
  
  <p>Seems quite simple, uh ? I manage to do it all in the MainWindow.xaml.cs (only using ObservableCollection, no 'PropertyChanged' yet), but I can't make it work in the ViewModel.</p>
  
  <p>Now my code :
   </p>
  
  <p><strong>Client.cs</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace DataBindingTestInViewModel
  {
      class Client
      {
          protected string _firstName;
          protected string _name;
  
          public string FirstName
          {
              get { return _firstName; }
              set { _firstName = value; }
          }
  
          public string Name
          {
              get { return _name; }
              set { _name = value; }
          }
      }
  }
  </code></pre>
  
  <p><strong>MainWindow.xaml</strong></p>
  
  <pre><code>&lt;Window x:Class="DataBindingTestInViewModel.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:local="clr-namespace:DataBindingTestInViewModel"
          mc:Ignorable="d"
          Title="MainWindow" Height="450" Width="800"&gt;
  
      &lt;Window.DataContext&gt;
          &lt;local:ViewModel /&gt;
      &lt;/Window.DataContext&gt;
  
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="Auto" /&gt;
              &lt;RowDefinition Height="*" /&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;ItemsControl Grid.Row="0" ItemsSource="{Binding Clients}"&gt;
              &lt;ItemsControl.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;Grid&gt;
                          &lt;Label Grid.Column="0" Content="{Binding FirstName}" /&gt;
                      &lt;/Grid&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ItemsControl.ItemTemplate&gt;
          &lt;/ItemsControl&gt;
  
          &lt;Button Grid.Row="1" Click="Button_Click"&gt;Add a client&lt;/Button&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>MainWindow.xaml.cs</strong> (create an instance of ViewModel + Button_Click event)</p>
  
  <pre><code>using System.Windows;
  
  namespace DataBindingTestInViewModel
  {
      /// &lt;summary&gt;
      /// Logique d'interaction pour MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          ViewModel viewmodel = new ViewModel();
  
          public MainWindow()
          {
              InitializeComponent();
          }
  
          private void Button_Click(object sender, RoutedEventArgs e)
          {
              viewmodel.AddClient();
          }
      }
  }
  </code></pre>
  
  <p><strong>ViewModel.cs</strong></p>
  
  <pre><code>using System.Collections.ObjectModel;
  using System.Windows;
  
  namespace DataBindingTestInViewModel
  {
      class ViewModel
      {
          private ObservableCollection&lt;Client&gt; _clients = new ObservableCollection&lt;Client&gt;();
  
          public ViewModel()
          {
              _clients.Add(new Client() { FirstName = "John", Name = "Doe" });
              _clients.Add(new Client() { FirstName = "Jane", Name = "Doe" });
              //MessageBox.Show("Constructeur du View Model appelé.");
          }
          public ObservableCollection&lt;Client&gt; Clients
          {
              get { return _clients; }
          }
  
          public void AddClient()
          {
              _clients.Add( new Client() { FirstName = "Donald", Name = "Trump" } );
              MessageBox.Show("First element : " + _clients[0].FirstName + "\n" +
                              "Third element : " + _clients[2].FirstName );
  
          }
      }
  }
  </code></pre>
  
  <p><strong>Results :</strong></p>
  
  <ul>
  <li>The "John Doe/Jane Doe" are displayed</li>
  <li>When I click the button it doesn't add the thing in the UI. (But the Messagebox works fine.)</li>
  </ul>
  
  <p><strong>What I think happens :</strong></p>
  
  <p>The MainWindow data context is binded to the ViewModel's Client instance. I create and add element in a new instance called in MainWindow - and that's not the one used in the datacontext.</p>
  
  <p><strong>Questions :</strong> </p>
  
  <ul>
  <li>Am I right ? If so, how to solve it (call the Viewmodel's instance's AddClient method in the MainWindow) ?</li>
  <li>Any other better (but simple, please !) methods ?</li>
  </ul>
  
  <p>I guess that'll be a piece of cake for y'all. Thank you !!</p>