title: WPF MVVM and Observablecollect
body: <p>I have a wpf application and I want to update my listview when I change the value through the UI using Observablecollect. But I don't get what I expect. When I change the value I won't update my list view. 
   View Code(Xaml)</p>
  
  <pre><code>&lt;UserControl x:Class="DataWatch.View.CompareData"
           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" 
           xmlns:ViewModels="clr-namespace:DataWatch.ViewModel"
           mc:Ignorable="d" 
           d:DesignHeight="340" d:DesignWidth="600"&gt;
  &lt;UserControl.DataContext&gt;
      &lt;ViewModels:CompareViewModel/&gt;
  &lt;/UserControl.DataContext&gt;
  &lt;Grid&gt;
      &lt;ListView HorizontalAlignment="Left" Name="comparelistview" VerticalAlignment="Top" Width="600" Height="340" ItemsSource="{Binding DisplayData}"&gt;
          &lt;ListView.View&gt;
  
              &lt;GridView&gt;
                  &lt;GridViewColumn Width="150" Header="Key"
                    DisplayMemberBinding="{Binding Path=Key}" /&gt;
                  &lt;GridViewColumn Width="150" Header="Project Data" 
                    DisplayMemberBinding="{Binding Path=ProjectData}" /&gt;
                  &lt;GridViewColumn Width="150" Header="Import Data" 
                    DisplayMemberBinding="{Binding Path=ImportData}"/&gt;
                  &lt;GridViewColumn Width="150" Header="State" 
                    DisplayMemberBinding="{Binding Path=State}"/&gt;
  
  
              &lt;/GridView&gt;
          &lt;/ListView.View&gt;
      &lt;/ListView&gt;
  
  &lt;/Grid&gt;
  </code></pre>
  
  <p>
   ViewModel</p>
  
  <pre><code>    namespace DataWatch.ViewModel
     {
  
       public class CompareViewModel
       {
          private ObservableCollection&lt;CompareDiplayData&gt; _displayData;
  
           public CompareViewModel()
          {
                _displayData = new ObservableCollection&lt;CompareDiplayData&gt;();
  
          }
                  public ObservableCollection&lt;CompareDiplayData&gt; DisplayData
          {
              get { return _displayData; } 
          }
      }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>    namespace DataWatch.Model
     {
       public class CompareDiplayData : INotifyPropertyChanged
       {
          private string _key;
          public string Key
          {
              set
              {
                  _key = value;
                  this.Changed("Key");
              }
              get
              {
                  return _key;
              }
          }
          private string _projectData;
  
          public string ProjectData
          {
              set
              {
                  _projectData = value;
                  this.Changed("ProjectData");
              }
              get
              {
                  return _projectData;
              }
          }
          private string _importData;
  
          public string ImportData
          {
              set
              {
                  _importData = value;
                  this.Changed("ImportData");
              }
              get
              {
                  return _importData;
              }
          }
          private string _state;
          public string State
          {
              set
              {
                  _state = value;
                  this.Changed("State");
              }
              get
              {
                  return _state;
              }
          }
          public event PropertyChangedEventHandler PropertyChanged;
          private void Changed(string PropertyName)
          {
              if (this.PropertyChanged != null)
                  this.PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
          }
      }
  
  }
  </code></pre>
  
  <p>When I change the value in displayData ,but Listview won't update the data.
    combobox view control</p>
  
  <pre><code>&lt;UserControl x:Class="DataWatch.View.SelectPanel"
           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" 
           xmlns:ViewModels="clr-namespace:DataWatch.ViewModel"
           xmlns:AttachProperty="clr-namespace:DataWatch.AttachedProperty"
           mc:Ignorable="d" 
           d:DesignHeight="30" d:DesignWidth="600"&gt;
  &lt;UserControl.DataContext&gt;
      &lt;ViewModels:CompareViewModel/&gt;
  &lt;/UserControl.DataContext&gt;
  &lt;Grid Name="good"&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="150"&gt;
          &lt;/ColumnDefinition&gt;
          &lt;ColumnDefinition Width="300"&gt;
          &lt;/ColumnDefinition&gt;
          &lt;ColumnDefinition Width="150"&gt;
  
          &lt;/ColumnDefinition&gt;
      &lt;/Grid.ColumnDefinitions&gt;
  
      &lt;ComboBox Height="23" HorizontalAlignment="Left"  Grid.Column="0" Grid.Row="0" Margin="15,4,6,4" x:Name="KeyComboBox" VerticalAlignment="Top" Width="120"  Text="Choose Key" AttachProperty:SelectionBehavior.SelectionChanged="{Binding SelectKeyCmd}"  SelectedItem="{Binding SelectedKey, Mode=TwoWay}" ItemsSource="{Binding KeyComboboxItem}"
        IsEditable="true"  IsReadOnly="true" 
        IsDropDownOpen="True" StaysOpenOnEdit="True"/&gt;
      &lt;ComboBox Height="23" HorizontalAlignment="Left" Grid.Column="1" Grid.Row="0" Margin="90,4,6,4" Name="compareitemcomBox" VerticalAlignment="Top" Width="120"  Text="Compare Item" AttachProperty:SelectionBehavior.SelectionChanged="{Binding SelectKeyCmd}" SelectedItem="{Binding SelectedComparedData, Mode=TwoWay}" ItemsSource="{Binding CompareComboboxItem}"
        IsEditable="true"  IsReadOnly="true" 
        IsDropDownOpen="True" StaysOpenOnEdit="True"/&gt;
      &lt;ComboBox Height="23" HorizontalAlignment="Left" Grid.Column="2" Grid.Row="0" Margin="15,4,6,4" Name="display" VerticalAlignment="Top" Width="120"  Text="Choose State" 
        IsEditable="true"  IsReadOnly="true" 
        IsDropDownOpen="True" StaysOpenOnEdit="True"/&gt;
  
  &lt;/Grid&gt;
  </code></pre>
  
  <p>
    Attach property</p>
  
  <pre><code> public class SelectionBehavior
  {
      public static DependencyProperty SelectionChangedProperty =
         DependencyProperty.RegisterAttached("SelectionChanged",
         typeof(ICommand),
         typeof(SelectionBehavior),
         new UIPropertyMetadata(SelectionBehavior.SelectedItemChanged));
      public static void SetSelectionChanged(DependencyObject target, ICommand value)
      {
          target.SetValue(SelectionBehavior.SelectionChangedProperty, value);
      }
      private static void SelectedItemChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
      {
          Selector element = target as Selector;
          if (element == null) throw new InvalidOperationException("This behavior can be attached to Selector item only.");
          if ((e.NewValue != null) &amp;&amp; (e.OldValue == null))
          {
              element.SelectionChanged += SelectionChanged;
          }
          else if ((e.NewValue == null) &amp;&amp; (e.OldValue != null))
          {
              element.SelectionChanged -= SelectionChanged;
          }
      }
      private static void SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
      {
          UIElement element = (UIElement)sender;
          ICommand command = (ICommand)element.GetValue(SelectionBehavior.SelectionChangedProperty);
          command.Execute(((Selector)sender).SelectedValue);
      }
  
  }
  </code></pre>
  
  <p>viewmodel </p>
  
  <pre><code>public class CompareViewModel 
  {
      private readonly ICommand _selectKeyCmd;
      private List&lt;string&gt; _pro_Property;
      private List&lt;string&gt; _imp_Property;
      private string selectedKey;
      private ObservableCollection&lt;string&gt; compareComboboxItem;
      private DataTable _dt;
     private CompareDiplayData domObject;
      private ObservableCollection&lt;CompareDiplayData&gt; _displayData;
  
  
  
      public CompareViewModel()
      {
                                 _displayData = new ObservableCollection&lt;CompareDiplayData&gt;();
          _selectKeyCmd = new RelayCommand(ComboboxChanged, ComboboxIsChanged);
  
      }
      private void ReslutData()
      {_displayData =null;
  
          if (SelectedKey != null &amp;&amp; SelectedComparedData != null)
          {
              foreach (DataRow pdr in _projectDt.Rows)
              {
  
                  CompareDiplayData cdd = new CompareDiplayData();
                  foreach (DataRow idr in _importDt.Rows)
                  {
  
                      if (pdr[SelectedKey].ToString() == idr[SelectedKey].ToString())
                      {
                          cdd.Key = pdr[SelectedKey].ToString();
                          cdd.ProjectData = pdr[SelectedComparedData].ToString();
                          cdd.ImportData = idr[SelectedComparedData].ToString();
                          if (pdr[SelectedComparedData].ToString() == idr[SelectedComparedData].ToString())
                              cdd.State = "Match";
                          else
                              cdd.State = "Mismatch";
                          _displayData.Add(cdd);
                      }
  
                  }
  
  
              }
          }
      }
   public ObservableCollection&lt;CompareDiplayData&gt; DisplayData
      {
          get { return _displayData; } 
      }
   public ICommand SelectKeyCmd
      {
          get { return _selectKeyCmd; }
      }
    private void ComboboxChanged(object obj)
      {
          ReslutData();
      }
      private bool ComboboxIsChanged(object obj)
      {
          return true;
      }`}`
  </code></pre>