title: Can you use an IValueConverter in a binding on the BorderBrush property?
body: <p>I have a class that implements <code>IValueConverter</code> that is intended to be used to convert a Boolean value into a <code>Brush</code>.  I'm trying to use the <code>IValueConverter</code> in a binding to the <code>BorderBrush</code> property of a <code>Border</code> Control:</p>
  
  <pre><code>&lt;Window x:Class="DomPicker.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:cc="clr-namespace:CustomControls;assembly=CustomControls"
          xmlns:sys="clr-namespace:System;assembly=mscorlib"
          DataContext="{Binding Path=Domains, RelativeSource={RelativeSource Self}}"
          Height="350"
          Title="My Title"
          Width="525"&gt;
  
      &lt;cc:CarSystemWindow.Resources&gt;
          &lt;cc:BooleanToBrushConverter x:Key="BrushConverter" True="Black" False="Transparent" /&gt;
  
          &lt;DataTemplate x:Name="DomainTemplate" DataType="DomainViewModel"&gt;
              &lt;Border BorderBrush="{Binding Converter=BrushConverter, Path=IsSelected}"&gt;
                  . . .
              &lt;/Border&gt;
          &lt;/DataTemplate&gt;
      &lt;/cc:CarSystemWindow.Resources&gt;
  
      &lt;Grid&gt;
          &lt;ListBox . . . Name="DomainListBox" /&gt;
      &lt;/Grid&gt;
  &lt;Window&gt;
  </code></pre>
  
  <p>Here is the code for the Domains property in the code behind:</p>
  
  <pre><code>public static readonly DependencyProperty DomainsProperty =
      DependencyProperty.Register( "Domains", typeof( ObservableCollection&lt;DomainViewModel&gt; ), typeof( MainWindow ), new PropertyMetadata( null ) );
  
  public ObservableCollection&lt;DomainViewModel&gt; Domains {
      get { return (ObservableCollection&lt;DomainViewModel&gt;) GetValue( DomainsProperty ); }
      set { SetValue( DomainsProperty, value ); }
  }
  </code></pre>
  
  <p>When I compile the code, which is by no means finished, I get a compiler error on the <code>BorderBrush</code> binding:</p>
  
  <pre><code>The TypeConverter for "IValueConverter" does not support converting from a string.
  </code></pre>
  
  <p>Here is the code for the <code>IValueConverter</code>:</p>
  
  <pre><code>public class BooleanConverter&lt;T&gt; : IValueConverter {
  
      public T False { get; set; }
      public T True { get; set; }
  
      public BooleanConverter( T trueValue, T falseValue ) {
          // Set the values of True and false to the values we were passed.
          True  = trueValue;
          False = falseValue;
      }
  
      public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) {
          return value is bool &amp;&amp; ( (bool) value ) ? True : False;
      }
  
      public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) {
          return value is T &amp;&amp; EqualityComparer&lt;T&gt;.Default.Equals( (T) value, True );
      }
  }
  
  [ValueConversion( typeof( bool ), typeof( Brush ) )]
  public class BooleanToBrushConverter : BooleanConverter&lt;Brush&gt; {
  
      /// &lt;summary&gt;
      /// Set us up so we convert true to a Black &lt;see cref="SolidColorBrush"/&gt; and
      /// false to a Red SolidColorBrush.
      /// &lt;/summary&gt;
      public BooleanToBrushConverter() :
          base( new SolidColorBrush( Colors.Black ), new SolidColorBrush( Colors.Red ) ) { }
  }
  </code></pre>
  
  <p>Can anyone tell me what I'm doing wrong?</p>