title: WPF:change background color of listview item
body: <p>how to change the foreground(even Background will do) of item in listview.
  i have a program which opens excel and check for broken links in the given sheet.
  i want to display the user the list of given links and whcih ever is broken. i want to change foreground to RED.
  i have bound the values to observablecollection. the collection is just collection of strings(WEB LINKS) and is working fine</p>
  
  <p>should i do multi binding like <a href="https://stackoverflow.com/questions/9324502/change-the-foreground-color-of-a-listview-item-only-in-one-column">here</a></p>
  
  <p><b>EDIT:-</b>
   have got one more problem on this. after creating the property and making all the changes. the WPF form is not getting updated with the values. i.e. the list box is not getting filled. neither the coloring is happening( not sure it is happening also. as i cant see them). </p>
  
  <p>here is my code. please excuse my coding i am new to WPF</p>
  
  <pre><code>&lt;Window x:Class="URLValide.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:Local="clr-namespace:URL_Validater.URLValide"
  Title="URL Validator" Height="269" Width="525" FontSize="13"
  ResizeMode="NoResize"&gt;
  
  &lt;Window.Resources&gt;
      &lt;ResourceDictionary&gt;
          &lt;Style x:Key="HighLight" TargetType="{x:Type Control}"&gt;
              &lt;Setter Property="Background" Value="Honeydew"/&gt;
              &lt;Setter Property="FontWeight" Value="UltraBlack"/&gt;
              &lt;Style.Triggers&gt;
                  &lt;Trigger Property="IsFocused" Value="True"&gt;
                      &lt;Setter Property="Effect"&gt;
                          &lt;Setter.Value&gt;
                              &lt;DropShadowEffect BlurRadius="40" Color="Beige" Direction="50" Opacity="0.5"/&gt;                                
                          &lt;/Setter.Value&gt;
                      &lt;/Setter&gt;
                      &lt;Setter Property="Background" Value="White"/&gt;
                  &lt;/Trigger&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
      &lt;/ResourceDictionary&gt;
  &lt;/Window.Resources&gt;
  
  &lt;DockPanel LastChildFill="True"&gt;
      &lt;Label DockPanel.Dock="Top" Name="WinHeader"  Height="30" Background="BurlyWood" FontFamily="Calibri" FontSize="20" FontWeight="Bold" FontStretch="Medium" VerticalAlignment="Top" HorizontalAlignment="Stretch" Margin="0,0,0,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Top"&gt;URL Validator&lt;/Label&gt;
      &lt;Grid DockPanel.Dock="Bottom" Background="Beige"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="auto"/&gt;
              &lt;ColumnDefinition Width="auto"/&gt;
              &lt;ColumnDefinition Width="auto"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="20" MaxHeight="30"/&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;TextBlock Grid.Column="0" Text="Current URL:"&gt;&lt;/TextBlock&gt;
          &lt;TextBlock Grid.Column="1"  Text="{Binding strCrnUrl}"  Width="370"&gt;&lt;/TextBlock&gt;
          &lt;TextBlock Grid.Column="2"  Text="10 of 100" HorizontalAlignment="Left" VerticalAlignment="Center"&gt;&lt;/TextBlock&gt;
      &lt;/Grid&gt;
      &lt;Grid DockPanel.Dock="Right" Width="154"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition MaxWidth="300" Width="19*" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition MaxHeight="55" MinHeight="10" Height="35*" /&gt;
              &lt;RowDefinition Height="165*"  MinHeight="10"  /&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;Label Name="LbleRight" BorderBrush="Black" BorderThickness="1" Margin="0,2" FontSize="13" Content="List Of URL's" Height="30" Grid.ColumnSpan="2" Grid.Row="0"&gt;&lt;/Label&gt;
          &lt;ListView Grid.Row="1" Background="Azure" ItemsSource="{Binding strPdfLst}" IsEnabled="True" Margin="0,0,0,1"&gt;&lt;/ListView&gt;            
      &lt;/Grid&gt;
  
      &lt;Grid DockPanel.Dock="Left"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="100*"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="30*" /&gt;
              &lt;RowDefinition Height="60*" /&gt;                
          &lt;/Grid.RowDefinitions&gt;            
          &lt;Label BorderBrush="Black" Name="lblFleSel" BorderThickness="1" Height="27" Margin="2,2,0,30" HorizontalAlignment="Left" Width="349"&gt;Select File To which Contains the list of URL's:&lt;/Label&gt;
          &lt;TextBox Name="txtbxFleNme" BorderBrush="Black" BorderThickness="1" Margin="2,34,0,0" Style="{StaticResource ResourceKey=HighLight}" HorizontalAlignment="Left" Width="272"&gt;&lt;/TextBox&gt;
          &lt;Button Name="btnFleSlec" Width="69" Height="27" Content="Browse" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="276,32,4,0"&gt;&lt;/Button&gt;
          &lt;Grid Grid.Row="1" Height="118" HorizontalAlignment="Left" Margin="0,1,0,0" Name="OptionGrid" VerticalAlignment="Top" Grid.RowSpan="2"&gt;
              &lt;StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Horizontal"&gt;
                  &lt;Border BorderBrush="Black" BorderThickness="1" Height="117" Margin="3,1,0,0" HorizontalAlignment="Stretch" Width="350"&gt;
                      &lt;!--&lt;StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Width="162" Height="118"&gt;                        
                      &lt;/StackPanel&gt;--&gt;
                      &lt;Grid Height="auto" HorizontalAlignment="Stretch" Width="335"&gt;
                          &lt;Grid.RowDefinitions&gt;
                              &lt;RowDefinition Height="10*"/&gt;
                              &lt;RowDefinition Height="10*"/&gt;
                              &lt;RowDefinition Height="10*"/&gt;
                              &lt;RowDefinition Height="10*"/&gt;
                              &lt;RowDefinition Height="10*"/&gt;
                          &lt;/Grid.RowDefinitions&gt;
                          &lt;CheckBox Name="chkboxHas" VerticalAlignment="Center" HorizontalAlignment="Center"&gt;Has Column Headers&lt;/CheckBox&gt;
                          &lt;Label Name="lblDesc" Height="auto" Margin="0,0,204,0" Grid.Row="1" HorizontalContentAlignment="Right" VerticalAlignment="Top"&gt;Description Column:&lt;/Label&gt;
                          &lt;ComboBox Grid.Row="1" Name="cmboxDescol"  Margin="131,0,0,0" Style="{StaticResource ResourceKey=HighLight}"&gt;&lt;/ComboBox&gt;
                          &lt;Label Name="lblUrlCol" Height="auto" Grid.Row="2" Margin="0,0,204,0" HorizontalContentAlignment="Right"&gt;URL's Column:&lt;/Label&gt;
                          &lt;ComboBox Name="cmboxUrlCol" Grid.Row="2" Margin="131,0,0,0" Style="{StaticResource ResourceKey=HighLight}"&gt;&lt;/ComboBox&gt;
                          &lt;Label Name="lblResCol" Height="auto" Grid.Row="3" Margin="0,0,196,0" HorizontalContentAlignment="Right"&gt;Result Column:&lt;/Label&gt;
                          &lt;ComboBox Name="cmboxResCol" Grid.Row="3" Margin="131,0,0,0" Style="{StaticResource ResourceKey=HighLight}"&gt;&lt;/ComboBox&gt;
                          &lt;Button Grid.Row="4" HorizontalAlignment="Center" VerticalAlignment="Center" Content="Validate URL links" Name="btnValidate"&gt;&lt;/Button&gt;
                      &lt;/Grid&gt;
                  &lt;/Border&gt;                    
              &lt;/StackPanel&gt;
          &lt;/Grid&gt;
      &lt;/Grid&gt;
  &lt;/DockPanel&gt;
  </code></pre>
  
  <p>
  i am not sure if i should be posting full code. but here is my class
  the button click will start the program.</p>
  
  <p>My class code:-</p>
  
  <pre><code>    Imports Microsoft
  Imports System
  Imports System.Net
  Imports System.Data
  Imports System.Windows
  Imports System.Windows.Forms
  Imports Excel = Microsoft.Office.Interop.Excel
  Imports System.Collections.ObjectModel
  Imports System.ComponentModel
  
  Namespace URLValide
  
      Public Class clsUrlCheck
          Implements INotifyPropertyChanged
  
          Public Event propertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
  
          Public exclApplic As New Excel.Application
          Public exclWkbOpe As Excel.Workbook
          Public exclWksAct As Excel.Worksheet
          Public exclRngUrl As Excel.Range
          Public exclRngDes As Excel.Range
          Public exclRngOut As Excel.Range
          Public intMaxRow As Long
          Public intCrtRow As Long
          Private _strTotlOf As String
          Private _strCrnUrl As String
          Private _ColorIndx As String
          Private _strPdfLst As ObservableCollection(Of String)
          Private _strhdrPdf As ObservableCollection(Of String)
  
  #Region "Region of poperties"
          Public Property strTotlOf() As String
              Get
                  Return _strTotlOf
              End Get
              Set(ByVal value As String)
                  _strTotlOf = value
                  Me.OnPropertyChanged("strTotlOf")
              End Set
          End Property
  
          Public Property strCrnUrl() As String
              Get
                  Return _strCrnUrl
              End Get
              Set(ByVal value As String)
                  _strCrnUrl = value
                  Me.OnPropertyChanged("strCrnUrl")
              End Set
          End Property
  
          Public Property strPdfLst As ObservableCollection(Of String)
              Get
                  Return _strPdfLst
              End Get
              Set(ByVal value As ObservableCollection(Of String))
                  _strPdfLst = value
                  Me.OnPropertyChanged("strPdfLst")
              End Set
          End Property
  
          Public Property strhdrPdf As ObservableCollection(Of String)
              Get
                  Return _strhdrPdf
              End Get
              Set(ByVal value As ObservableCollection(Of String))
                  _strhdrPdf = value
                  Me.OnPropertyChanged("strhdrPdf")
              End Set
          End Property
  
          Public Property ColorIndx As String
              Get
                  Return _ColorIndx
              End Get
              Set(ByVal value As String)
                  _ColorIndx = value
                  Me.OnPropertyChanged("ColorIndx")
              End Set
          End Property
  
          Private Sub OnPropertyChanged(ByVal propertyName As String)
              RaiseEvent propertyChanged(Me, New PropertyChangedEventArgs(propertyName))
          End Sub
  #End Region
  
  #Region "function of Validating the URL's"
          Public Function UrlCheck(ByVal strUrlReq As String)
  
              Try
  
                  Dim WebReq As Net.HttpWebRequest = Net.HttpWebRequest.Create(strUrlReq)
                  WebReq.Method = "Head"
                  WebReq.Timeout = 5000
                  Using Response = WebReq.GetResponse()
                      Return True
                  End Using
  
              Catch ex As Exception
                  ColorIndx = "True"
                  Return False
  
              End Try
  
          End Function
  #End Region
  
  #Region "Start Function"
          Sub suStart()
              Dim blnValid As Boolean
  
  
              'strPdfLst.Clear()
              'strPdfLst = makeList(exclRngUrl.Column, False)
              If exclRngDes.Value = "Make Desc" Then
                  strPdfLst = makeList(exclRngUrl.Column, True)
                  exclRngDes.Delete()
              Else
                  strPdfLst = makeList(exclRngUrl.Column, False)
              End If
  
              For Each exclRngEch As Excel.Range In exclRngUrl
                  strCrnUrl = exclRngEch.Text
                  strTotlOf = exclRngEch.Row &amp; "OF" &amp; intMaxRow
                  blnValid = UrlCheck(exclRngEch.Value.ToString)
                  If blnValid Then
                      exclWksAct.Cells(exclRngEch.Row, exclRngOut.Column).value = "Web Page Present"
                  Else
                      exclWksAct.Cells(exclRngEch.Row, exclRngOut.Column).value = "Web Page Error"
  
                  End If
  
              Next
  
  
          End Sub
  
          Function makeList(ByVal intColNum As Long, ByVal blnMkeStr As Boolean) As ObservableCollection(Of String)
  
              Dim ObsColTem As ObservableCollection(Of String) = New ObservableCollection(Of String)
  
              If Not blnMkeStr Then
                  For intLopCnt As Int32 = intCrtRow To intMaxRow
                      ObsColTem.Add(exclWksAct.Cells(intLopCnt, intColNum).Text)
                  Next
              Else
                  For intLopCnt As Int32 = intCrtRow To intMaxRow
                      Dim strDesc As String = Mid(exclWksAct.Cells(intLopCnt, intColNum).Text, InStrRev(exclWksAct.Cells(intLopCnt, intColNum).Text, "/", , CompareMethod.Text) + 1)
                      ObsColTem.Add(strDesc)
                  Next
              End If
              Return ObsColTem
          End Function
  #End Region
  
      End Class
  End Namespace
  </code></pre>