title: Bind image control to BitmapImage in my class
body: <p>Whenever I wanted to display an image in the past, I bound the image path to the image's source property. Too easy. </p>
  
  <p>Now I want to change the image and always show the image <em>with</em> the latest changes. The change image is saved in a <code>BitmapImage</code> property inside my class. So instead of asking the image control to load the image from disc, I wanted to bind it directly to my <code>BitmapImage</code> property. But the image does not show. </p>
  
  <p>Then (just for testing) I created a value converter, used the path to the image in there to create a <code>BitmapImage</code> and returned that to the control - and the image shows.</p>
  
  <p>Again: Creating a <code>BitmapImage</code> from a path inside the coverter works. Binding the image control to a <code>BitmapImage</code> property that is created in my class with the same code fails.</p>
  
  <p>That describes the same problem, but the "solution" doesn't work. (I wonder why it is marked as solved, since the OP made the same comment)</p>
  
  <p><a href="https://stackoverflow.com//questions/7263509/directly-binding-a-bitmapimage-created-inside-a-class-bound-to-a-listbox-in-wpf">https://stackoverflow.com//questions/7263509/directly-binding-a-bitmapimage-created-inside-a-class-bound-to-a-listbox-in-wpf</a></p>
  
  <p>EDIT: here is some code</p>
  
  <p>This is the converter that successfully creates a visible image.</p>
  
  <pre><code>public class BsConverter : IValueConverter
  {
      public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          BitmapImage bi = new BitmapImage(new Uri(value.ToString()));
  
          return bi;
      }
  
      public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          throw new NotImplementedException();
      }
  }
  </code></pre>
  
  <p>... and the XAML binding that does show the image. <code>File</code> is of type <code>FileInfo</code> and <code>FullName</code> holds the complete path.</p>
  
  <pre><code>&lt;Image MinHeight="100" MinWidth="100" Source="{Binding SelectedImage.File.FullName, Converter={StaticResource BsConverter}}"/&gt;
  </code></pre>
  
  <p>I have a property <code>BitmapImage image { get; set; }</code> that I initialize in the constructor of my class: </p>
  
  <pre><code>image = new BitmapImage();
  image.BeginInit();
  image.UriSource = new Uri(file.FullName);
  image.CacheOption = BitmapCacheOption.OnLoad;
  image.EndInit();
  </code></pre>
  
  <p>...and the binding. But - no joy. The image is not displayed.</p>
  
  <pre><code>&lt;Image MinHeight="100" MinWidth="100" Source="{Binding SelectedImage.image}"/&gt;
  </code></pre>