title: WPF Color a ListBoxItem based on a property
body: <p>I have looked at <a href="https://stackoverflow.com/questions/6182563/color-a-wpf-listbox-item-based-on-a-property">this answer</a>, but it is not working for me for some reason.  I am using an Observable Collection of LookupEntity objects:</p>
  
  <pre><code>public class LookupEntity
  {
      public bool IsSelected { get; set; }
      public int Id { get; set; }
      public string Code { get; set; }
      public string Title { get; set; }
      public string Description { get; set; }
      public bool IsInactive { get; set; }
   }
  </code></pre>
  
  <p>What I need is for the background color of an inactive item (IsInactive=True) to be different than the other items.  I have tried two approaches.  The first is to use a DataTrigger and a Template.  This should work, but it is not:</p>
  
  <pre><code>    &lt;ListBox x:Name="RecordList"
      Grid.Row="2"
      MinWidth="200"
      ItemsSource="{Binding MaintenanceList, Mode=TwoWay}"
      HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
      VerticalAlignment="Stretch"
      BorderThickness="0"
      SelectedValue="{Binding SelectedItem, Mode=TwoWay}"                            
      IsEnabled="{Binding ContentVM.AddEnabled}"
      SelectionChanged="ListBox_SelectionChanged"&gt;
      &lt;ListBox.Resources&gt;
          &lt;Style TargetType="ListBoxItem"&gt;
              &lt;Style.Triggers&gt;
                  &lt;DataTrigger Binding="{Binding Path=IsInactive}" Value="True"&gt;
                      &lt;Setter Property="Background" Value="PaleVioletRed"/&gt;
                  &lt;/DataTrigger&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
          &lt;DataTemplate DataType="{x:Type utility:LookupEntity}"&gt;
              &lt;TextBlock 
          Text="{Binding Title}"
          ToolTip="{Binding Description}"
          TextWrapping="NoWrap"
          HorizontalAlignment="Left"/&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListBox.Resources&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>The second approach works, but it depends on a Background Color property in the LookupEntity object.  I don't like this approach because it gives display responsibility to an object that shouldn't have any knowledge of how it's displayed.  Adding this property to the LookupEntity:</p>
  
  <pre><code>    public SolidColorBrush BackgroundColor
      {
          get { return IsInactive ? Brushes.PaleVioletRed : Brushes.Transparent; }
      }
  </code></pre>
  
  <p>And binding the Background property of the DataTemplate works, but it's not acceptable.  </p>
  
  <pre><code>    &lt;ListBox.Resources&gt;
          &lt;DataTemplate DataType="{x:Type utility:LookupEntity}"&gt;
              &lt;TextBlock 
          Text="{Binding Title}"
          ToolTip="{Binding Description}"
          TextWrapping="NoWrap"
          HorizontalAlignment="Left"
          Background="{Binding BackgroundColor}"/&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListBox.Resources&gt;
  </code></pre>
  
  <p>I'd like to place the responsibility for the Background color in a skin / resource, but I can't with this setup.  Is there something I've missed? </p>