title: How to set the SystemColors.HighlightBrushKey in WPF with a Converter
body: <p>I im trying to set the SystemColors.HighlightBrushKey always a bit darker than the Background of the selected Row.
  Therefore im using this Code:</p>
  
  <p>App.xaml:</p>
  
  <p>
      </p>
  
  <pre><code>    &lt;WPFTests2:SelectionBackgroundConverter x:Key="SelectionBackgroundConverter"/&gt;
  
      &lt;SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="{Binding Background, Converter={StaticResource SelectionBackgroundConverter}}"/&gt;
  
  &lt;/Application.Resources&gt;
  </code></pre>
  
  <p></p>
  
  <p>Window1.xaml:</p>
  
  <pre><code>&lt;Window x:Class="WPFTests2.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Window1" Height="300" Width="300" Loaded="Window_Loaded"&gt;
  &lt;Grid&gt;
      &lt;ListBox x:Name="LB" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>Window1.xaml.cs:</p>
  
  <pre><code>using System; 
  using System.Globalization;
  using System.Windows;
  using System.Windows.Data;
  using System.Windows.Media;
  
  namespace WPFTests2
  {
  /// &lt;summary&gt;
  /// Interaction logic for Window1.xaml
  /// &lt;/summary&gt;
  public partial class Window1 : Window
  {
      public Window1()
      {
          InitializeComponent();
      }
  
      private void Window_Loaded(object sender, RoutedEventArgs e)
      {
          LB.Items.Add("Text1");
          LB.Items.Add("Text2");
          LB.Items.Add("Text3");
          LB.Items.Add("Text4");
          LB.Items.Add("Text5");
      }
  }
  
  public class SelectionBackgroundConverter : IValueConverter
  {
      public object Convert(object value, Type targetType,
                            object parameter, CultureInfo culture)
      {
          if (value != null)
          {
              SolidColorBrush brush = (SolidColorBrush)value;
              Color newCol = brush.Color;
              newCol.R -= 10;
              newCol.G -= 10;
              newCol.B -= 10;
              BrushConverter conv = new BrushConverter();
              Brush newBrush = (Brush)conv.ConvertTo(newCol, typeof(Brush));
              return newBrush;
          }
          return Brushes.Transparent;
      }
  
      public object ConvertBack(object value, Type targetType,
                                object parameter, CultureInfo culture)
      {
          //never called
          return null;
      }
  }
  }
  </code></pre>
  
  <p>The Problem is that the Converter never gets called...
  Does anyone know how to set the Background of the selected Row a bit darker than it was before selecting it?</p>
  
  <p>Any help is appreciated!</p>
  
  <p><strong>Update</strong></p>
  
  <p>It looks like its working but unfortunately not completely.
  I've corrected the Converter to look like this:</p>
  
  <pre><code>public class SelectionBackgroundConverter : IValueConverter
  {
      public object Convert(object value, Type targetType,
                            object parameter, CultureInfo culture)
      {
          if (value != null)
          {
              SolidColorBrush brush = (SolidColorBrush)value;
              Color newCol = brush.Color;
              newCol.R -= 10;
              newCol.G -= 10;
              newCol.B -= 10;
              return new SolidColorBrush(newCol);
          }
          return Brushes.Transparent;
      }
  
      public object ConvertBack(object value, Type targetType,
                                object parameter, CultureInfo culture)
      {
          // we don't intend this to ever be called
          return null;
      }
  </code></pre>
  
  <p>Now the problem is that the Converter only gets called once. I mean if I start the Program and click on any Row the Converter gets called. If I then click into another Row, DataGrid or Control the Converter doesn't get called.</p>
  
  <p>Any Idea how to fix this?</p>