title: ObservableCollection not updated to UI when property changed
body: <p><strong>Question</strong>: ObservableCollection not updated to UI when property changed</p>
  
  <p><strong>What I have tried</strong>:</p>
  
  <p>XAML view:</p>
  
  <pre><code>&lt;UserControl x:Class="FlexilineDotNetGui.Flexiline.UserControls.UCRealestate"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
               mc:Ignorable="d" 
               xmlns:translations="clr-namespace:FlexilineDotNetGui.Flexiline.Translations"
               xmlns:viewModels="clr-namespace:FlexilineDotNetGui.Flexiline.ViewModels"
               x:Name="Realestate"
               DataContext="{StaticResource vmRealestate}"&gt;
      &lt;Grid Margin="5"&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="Auto"/&gt;
              &lt;RowDefinition Height="Auto"/&gt;
              &lt;RowDefinition Height="Auto"/&gt;
              &lt;RowDefinition Height="Auto"/&gt;
              &lt;RowDefinition Height="Auto"/&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Grid Grid.Row="0" &gt;
              &lt;Grid&gt;
                  &lt;Grid.RowDefinitions&gt;
                      &lt;RowDefinition Height="Auto"/&gt;
                      &lt;RowDefinition Height="Auto"/&gt;
                      &lt;RowDefinition/&gt;
                      &lt;RowDefinition Height="Auto"/&gt;
                  &lt;/Grid.RowDefinitions&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition Width="*"/&gt;
                      &lt;ColumnDefinition Width="Auto"/&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
                  &lt;DataGrid Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" Height="200" Margin="5"
                            ItemsSource="{Binding Panden, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="False" 
                            CanUserAddRows="False" IsReadOnly="True" SelectedItem="{Binding Pand}"&gt;
                      &lt;DataGrid.Columns&gt;
                          &lt;DataGridTextColumn Header="{x:Static translations:UCRealestate.RegistrationType}" Binding="{Binding RegistrationType, Mode=TwoWay}" Width="Auto"/&gt;
                      &lt;/DataGrid.Columns&gt;
                  &lt;/DataGrid&gt;
                  &lt;Button Grid.Column="1"  Grid.Row="0" Background="Transparent"
                          Width="20" Height="20" Padding="0" Margin="5" Command="{Binding AddPandCMD}"
                          CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type viewModels:RealestateViewModel}}}"&gt;
                      &lt;Image Source="/Flexiline;component/Resources/New_16x16.ico"/&gt;
                  &lt;/Button&gt;
                  &lt;Button Grid.Row="1" Grid.Column="1" VerticalAlignment="Top" 
                          Width="20" Height="20" Padding="0" Background="Transparent" Margin="5" Command="{Binding DeletePandCMD}"
                          CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type viewModels:RealestateViewModel}}}"&gt;
                      &lt;Image Source="/Flexiline;component/Resources/Delete_16x16.ico"/&gt;
                  &lt;/Button&gt;
                  &lt;Grid Grid.Row="3" Margin="5"&gt;
                      &lt;Grid&gt;
                          &lt;Grid.RowDefinitions&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                          &lt;/Grid.RowDefinitions&gt;
                          &lt;Grid.ColumnDefinitions&gt;
                              &lt;ColumnDefinition Width="Auto"/&gt;
                              &lt;ColumnDefinition Width="*"/&gt;
                              &lt;ColumnDefinition Width="Auto"/&gt;
                              &lt;ColumnDefinition Width="*"/&gt;
                          &lt;/Grid.ColumnDefinitions&gt;
                          &lt;Grid Grid.Row="1" Grid.Column="1" Margin="0,5"&gt;
                              &lt;Grid.ColumnDefinitions&gt;
                                  &lt;ColumnDefinition Width="*" MaxWidth="100"/&gt;
                                  &lt;ColumnDefinition Width="Auto" /&gt;
                                  &lt;ColumnDefinition Width="*"/&gt;
                              &lt;/Grid.ColumnDefinitions&gt;
                          &lt;/Grid&gt;         
                          &lt;Label Grid.Row="2" Grid.Column="2" Content="{x:Static translations:UCRealestate.RegistrationType}" HorizontalContentAlignment="Right" VerticalAlignment="Center"/&gt;
                          &lt;ComboBox Grid.Row="2" Grid.Column="3" Margin="5" ItemsSource="{Binding AardInschrijving, UpdateSourceTrigger=PropertyChanged}" SelectedValue="{Binding SelectedAardInschrijving, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" DisplayMemberPath="Description" SelectedValuePath="FlexKey"/&gt;
                      &lt;/Grid&gt;
                  &lt;/Grid&gt;
              &lt;/Grid&gt;
          &lt;/Grid&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>ViewModel :</p>
  
  <pre><code>using FlexilineDotNet.SharedDomainLogic.Models.CommunicationModels;
  using FlexilineDotNetGui.Domain.Controls;
  using FlexilineDotNetGui.Domain.Models;
  using GalaSoft.MvvmLight.Command;
  using System;
  using System.Collections.Generic;
  using System.Collections.ObjectModel;
  using System.ComponentModel;
  using System.Linq;
  using System.Runtime.CompilerServices;
  using System.Windows;
  using System.Windows.Data;
  
  namespace FlexilineDotNetGui.Flexiline.ViewModels
  {
      public class RealestateViewModel : ANavigationPaneSubViewModel, INotifyPropertyChanged
      {
          BorgRealestate _borgRealestate = new BorgRealestate();
          ObservableCollection&lt;BorgRealestate&gt; ocPanden = new ObservableCollection&lt;BorgRealestate&gt;();
          private DomainController _controller = DomainController.GetInstance();
  
          public RelayCommand&lt;object&gt; AddPandCMD { get; private set; }
          public RelayCommand&lt;object&gt; DeletePandCMD { get; private set; }
  
          #region "properties"
  
          public ObservableCollection&lt;BorgRealestate&gt; Panden
          {
              get
              {           
                  return ocPanden ?? (ocPanden = new ObservableCollection&lt;BorgRealestate&gt;());
              }
              set
              {
                  if (ocPanden == value)
                      return;
  
                  ocPanden = value;
                  OnPropertyChanged("Panden");
              }
          }
  
          //public ObservableCollection&lt;BorgRealestate&gt; Panden { get; }
  
  
          public BorgRealestate Pand
          {
              get
              {
                  return _borgRealestate ?? (_borgRealestate = new BorgRealestate());
              }
              set
              {
                  if (value == _borgRealestate) return;
                  _borgRealestate = value;
                  OnPropertyChanged();
                  OnPropertyChanged("Panden");
              }
          }
  
  
          public List&lt;DropDownItem&gt; AardInschrijving { get { return _controller.GetDropDownItemsByType("AardInschrijving"); } }
  
          private DropDownItem SelectedAardInschrijvingDI
          {
              get
              {
                  DropDownItem test = _controller.GetDropDownItemsByType("AardInschrijving").FirstOrDefault(x =&gt; x.FlexKey == _borgRealestate?.RegistrationType);
                  if (test == null)
                  {
                      test = _controller.GetDropDownItemsByType("AardInschrijving").FirstOrDefault();
                  }
                  return test;
              }
              set
              {
                  OnPropertyChanged();
                  OnPropertyChanged("Panden");
              }
          }
  
          public int SelectedAardInschrijving
          {
              get
              {
                  return SelectedAardInschrijvingDI.FlexKey;
              }
              set
              {
                  if (value == Pand?.RegistrationType) return;
                  Pand.RegistrationType = value;
                  OnPropertyChanged();
                  OnPropertyChanged("Panden");
              }
          }
  
          public string SelectedAardInschrijvingText
          {
              get
              {
                  return SelectedAardInschrijvingDI.Description;
              }
          }
  
  
          #endregion
  
          #region "ctor"
  
          public RealestateViewModel()
          {
              //Panden = new ObservableCollection&lt;BorgRealestate&gt;();
              AddPandCMD = new RelayCommand&lt;object&gt;(o =&gt; AddPand());
              DeletePandCMD = new RelayCommand&lt;object&gt;(o =&gt; DeletePand());
          }
  
          #endregion
  
          #region "methods"
  
          private void AddPand()
          {
              BorgRealestate newBorgRealestate = new BorgRealestate { RegistrationType = SelectedAardInschrijving };
              Panden.Add(newBorgRealestate);      
          }
  
          private void DeletePand()
          {
              Panden.Remove(Pand);
          }
  
          #endregion
      }
  }  
  </code></pre>
  
  <p><strong>Problem description:</strong></p>
  
  <p>When I Update the combobox value, it's updated in the "Panden" property when I check with a breakpoint but the datagrid in the view is not updated. The problem exists with Oneway and also with TwoWay as I defined in datagrid columns. I have both modes tried.</p>
  
  <p>The views are inside a dxnavbar control, when I switch between navbar items and back then the view is updated OK.</p>
  
  <p>EDIT:</p>
  
  <p>When the application starts, the Panden list is indeed null, I had forgotten to mention something....</p>
  
  <p>In my view there is a datagrid with a button where I add items to the observable collection where also some of the properies as example nature inscription combobox value is shown in datagrid. This button is then connected to a relay command. That is the collection that i have binded to the datagridview.</p>
  
  <p>the getter of the property property is not empty and is therefore filled with the correct values, only the changes do not change in the view.</p>
  
  <p>it is indeed normal that the collection is null if no "Pand" items are added to the "Panden" collection via the provided button on the UI (relaycommand). But the "Pand" item in de datagrid will not update after i change a value from the combobox after adding an item with the button to the collection. </p>
  
  <p><strong>EDIT 21/11 08:54</strong></p>
  
  <p>This is the logic for adding the pand:</p>
  
  <pre><code>private void AddPand()
          {
              BorgRealestate newBorgRealestate = new BorgRealestate { RegistrationType = SelectedAardInschrijving };
              Panden.Add(newBorgRealestate);      
          }
  </code></pre>
  
  <p>But after i add i see the items gets added to the collection and get also updated in the collection after the combobox value changed only not in ui. (when the row in the datagrid have the focus)</p>