title: Set LinearLayout background color via boolean value
body: <p>I'm trying to use an MvxValueConverter to set the background color of a LinearLayout based on a boolean value. The converter looks like this:</p>
  
  <pre><code>public class BackgroundColorValueConverter : MvxValueConverter&lt;bool, MvxColor&gt;
  {
      private static readonly MvxColor TrueBGColor = new MvxColor(0xDB, 0xFF, 0xCE);
      private static readonly MvxColor FalseBGColor = new MvxColor(0xD6, 0xF6, 0xFF);
  
      protected override MvxColor Convert(bool value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          return value ? TrueBGColor : FalseBGColor;
      }
  }
  </code></pre>
  
  <p>In my AXML layout, I have the following code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:local="http://schemas.android.com/apk/res-auto"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      local:MvxBind="BackgroundColor MyBooleanValue, Converter=BackgroundColor"&gt;
    &lt;TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textSize="18dp"
        local:MvxBind="Text MyText" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I'm getting the following error:</p>
  
  <pre><code>Failed to create target binding for binding BackgroundColor for MyBooleanValue
  </code></pre>
  
  <p>The full error trace is as follows:</p>
  
  <pre><code>MvxBind:Error:  8.58 Problem seen during binding execution for binding BackgroundColor for MyBooleanValue - problem InvalidCastException: Cannot cast from source type to destination type.
  03-05 14:18:46.434 I/mono-stdout(16474): MvxBind:Error:  8.58 Problem seen during binding execution for binding BackgroundColor for MyBooleanValue - problem InvalidCastException: Cannot cast from source type to destination type.
  03-05 14:18:46.434 I/mono-stdout(16474):      at Cirrious.MvvmCross.Plugins.Color.Droid.BindingTargets.MvxViewBackgroundColorBinding.SetValueImpl (System.Object target, System.Object value) [0x00000] in &lt;filename unknown&gt;:0 
        at Cirrious.MvvmCross.Plugins.Color.Droid.BindingTargets.MvxViewBackgroundColorBinding.SetValueImpl (System.Object target, System.Object value) [0x00000] in &lt;filename unknown&gt;:0 
    at Cirrious.MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x00000] in &lt;filename unknown&gt;:0 
  03-05 14:18:46.434 I/mono-stdout(16474):   at Cirrious.MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x00000] in &lt;filename unknown&gt;:0 
    at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (System.Object value) [0x00000] in &lt;filename unknown&gt;:0 
  </code></pre>
  
  <p>So, I'm honestly not sure where to go from here. Is what I'm attempting possible? Am I using the right MvvmCross converter? Any pointers would be much appreciated.</p>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <p>Changing the converter to:</p>
  
  <pre><code>public class BackgroundColorValueConverter : MvxColorValueConverter
  {
      private static readonly MvxColor TrueBGColor = new MvxColor(0xDB, 0xFF, 0xCE);
      private static readonly MvxColor FalseBGColor = new MvxColor(0xD6, 0xF6, 0xFF);
  
      protected override MvxColor Convert(object value, object parameter, System.Globalization.CultureInfo culture)
      {
          return (bool)value ? TrueBGColor : FalseBGColor;
      }
  }
  </code></pre>
  
  <p>... resolved my problem. I also had <code>TextColor MyBooleanValue, Converter=TextColor</code> on my <code>LinearLayout</code>, which functioned similarly to <code>BackgroundColorValueConverter</code>, and I was getting the same error about failing to create target bindings.</p>
  
  <p>Once I changed my AXML to read:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:local="http://schemas.android.com/apk/res-auto"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      local:MvxBind="BackgroundColor MyBooleanValue, Converter=BackgroundColor"&gt;
    &lt;TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textSize="18dp"
        local:MvxBind="Text MyText; TextColor MyBooleanValue, Converter=TextColor" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>... everything worked as intended. For anyone who happens to stumble across this in the future: don't try to bind <code>TextColor</code> on a <code>LinearLayout</code>, because it doesn't work like that!</p>