title: Imagebrush image source binding converter
body: <p>I'm using an xml as source of my application via binding. in the xml there is a list of folders and  a path for a sample image for each folder. The folder list is binded to listbox, and another display is binded to the selected item of the listbox, which is an item of the xml list (type XmlNode). I added the opertunity to add and remove items using the XmlDocument which was copied from the xml by the XmlProvider and save it to the source file.</p>
  
  <p>The problem begins when the source list is empty, either at the application load time, or after removing all of the items. at this point all of the binded values of the display are null. I solved all of the bindings with the binding's TargetNullValue property, exept the canvas background imagebrush image_source property which shows nothing.</p>
  
  <p>I tried to use a converter, but when I debuged it I saw something weird. if there were items in the list the converter returned what is should and the image was displayed, but if the list was empty, the converter returned what it should and no image was shown!
  plz help me.</p>
  
  <p>Code:</p>
  
  <p>XML:</p>
  
  <pre><code>  &lt;Folders&gt;
      &lt;Folder Id="1"&gt;
        &lt;Path&gt;folder3\1&lt;/Path&gt;
        &lt;SampleImage&gt;C:\images\2011-09-22\site3\1\6.jpg&lt;/SampleImage&gt;
      &lt;/Folder&gt;
    &lt;/Folders&gt;
  </code></pre>
  
  <p>XAML:</p>
  
  <pre><code>    &lt;Canvas.Background&gt;
        &lt;ImageBrush x:Name="SampleImage" Stretch="Uniform" &gt;
          &lt;ImageBrush.ImageSource&gt;
            &lt;MultiBinding Converter="{StaticResource ImageConverter}" Mode="OneWay"&gt;
              &lt;Binding XPath="./SampleImage" /&gt;
              &lt;Binding Source="C:\images\SampleImages\no_image.jpg"/&gt;
            &lt;/MultiBinding&gt;
          &lt;/ImageBrush.ImageSource&gt;
        &lt;/ImageBrush&gt;
     &lt;/Canvas.Background&gt;
  </code></pre>
  
  <p>c#:</p>
  
  <pre><code>public class ImageConverter : IMultiValueConverter
  {
      public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          ImageSourceConverter imageConverter = new ImageSourceConverter();
          bool bool1=value[0].Equals(DependencyProperty.UnsetValue);
          if (value[0] != null &amp;&amp;!bool1) //if the source isn't null
          {
               //this works fine
               return imageConverter.ConvertFromString(value[0].ToString());
          }
          //here the converter returns the right object but the alternate image isn't shown and the background left blank
          return imageConverter.ConvertFromString(value[1].ToString());
  
          //here too the converter returns the right object but the alternate image isn't shown and the background left blank
          //return imageConverter.ConvertFromString(@"C:\images\SampleImages\no_image.jpg");
  
      }
  
  
      public object[] ConvertBack(object value, Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          return null;
      }
  
  }
  </code></pre>