title: C# WPF OnPropertyChanged Within a foreach loop
body: <p>I have been trying to learn and take advantage of  WPF and databinding. I have a listview that has a column that will display one of three images as shown in this snippet:</p>
  
  <pre><code>&lt;GridViewColumn Header="Status" Width="50"&gt;
    &lt;GridViewColumn.CellTemplate&gt;
      &lt;DataTemplate&gt;
        &lt;Image x:Name="TheImage" Height="18"/&gt;
          &lt;DataTemplate.Triggers&gt;
            &lt;DataTrigger Binding="{Binding Path=Status}" Value="queued"&gt;
              &lt;Setter TargetName="TheImage" Property="Source" Value="Images\que_48.png" /&gt;
            &lt;/DataTrigger&gt;
            &lt;DataTrigger Binding="{Binding Path=Status}" Value="completed"&gt;
              &lt;Setter TargetName="TheImage" Property="Source" Value="Images\complete_48.png" /&gt;
            &lt;/DataTrigger&gt;
            &lt;DataTrigger Binding="{Binding Path=Status}" Value="failed"&gt;
              &lt;Setter TargetName="TheImage" Property="Source" Value="Images\fail_48.png" /&gt;
            &lt;/DataTrigger&gt;
          &lt;/DataTemplate.Triggers&gt;
        &lt;/DataTemplate&gt;
      &lt;/GridViewColumn.CellTemplate&gt;
    &lt;/GridViewColumn&gt;
  </code></pre>
  
  <p>I have a class (BatchQueueItem) that has among it this code for handling the PropertyChange Event:</p>
  
  <pre><code>public string status;
    public string Status
    {
      get { return status; }
      set 
      { 
        status = value;
        OnPropertyChanged("Status");
      }            
    }
    // Create the OnPropertyChanged method to raise the event
  
    public event PropertyChangedEventHandler PropertyChanged;    
    private void OnPropertyChanged(string status)
    {
      if (PropertyChanged != null)
      {
        PropertyChanged(this, new PropertyChangedEventArgs(status));
      }
    }
  </code></pre>
  
  <p>And I have a button on the listview window page:</p>
  
  <pre><code>private void btnStart_Click(object sender, RoutedEventArgs e)
  {
    foreach (var item in listView1.Items)
    {
      BatchQueueItem bqi = (BatchQueueItem)item;
      string currFile = bqi.CurrFile;
      if (mainWindow.isIsbnInFileName(ref currFile))
      {
         bqi.Status = "completed";
      }
      else
      {
        bqi.Status = "failed";
      }
    }
  }
  </code></pre>
  
  <p>The problem I am having is that the images do not update until after the foreach loop has completed and the btnStart_Click() method has completed. Once that happens, all the images update as expected, just all at once not iteratively. </p>
  
  <p>What I am wanting, and what I thought would happen, was that each iteration of the foreach loop would update the corresponding row's image. Undoubtedly I am missing something important about how this all works. Any tips?</p>