title: How to change WPF listview row background colour dynamically?
body: <p>I am new to WPF, I have the following xaml code for list view:</p>
  
  <pre><code>&lt;ListView x:Name="listView1" ItemsSource="{Binding Processes1}"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="470" Margin="10,95,150,6" Width="565" SelectionChanged="NetscalerCfgView_listView1_SelectionChanged"&gt;
     &lt;ListView.View&gt;
         &lt;GridView&gt;
             &lt;GridViewColumn Header="Line"  DisplayMemberBinding="{Binding srcCfgLineNum}"/&gt;
             &lt;GridViewColumn Header="Source Config" DisplayMemberBinding="{Binding srcConfigText}"/&gt;
         &lt;/GridView&gt;
     &lt;/ListView.View&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p>I have the class SrcListViewInfo which I am displaying in listview:</p>
  
  <pre><code>public class SrcListViewInfo
  {
      public int srcCfgLineNum { get; set; }
      public string srcConfigText { get; set; }
  }
  </code></pre>
  
  <p>I have declared it in windows load event like this:</p>
  
  <pre><code>public ObservableCollection&lt;SrcListViewInfo&gt; processes1 = null;
  processes1 = new ObservableCollection&lt;SrcListViewInfo&gt;();
  </code></pre>
  
  <p>I want to color the  row background dynamically in a different function under different  cases dynamically, for example:</p>
  
  <pre><code>case DiffResultSpanStatus.DeleteSource:
      for (i = 0; i &lt; drs.Length; i++)
      {
          SrcListViewInfo newInfo = new SrcListViewInfo();
          newInfo.BackgroundColor = new SolidColorBrush(Colors.Red);
          // newInfo.BackgroundColor = Brushes.Red;
          newInfo.srcCfgLineNum = cnt;
          newInfo.srcConfigText = ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line;
          // newInfo.BackgroundColor = Brushes.Red; &lt;&lt; want to set the color like this.
  </code></pre>
  
  <p>I have tried solid brush but it does not seem to be working correctly.</p>