title: WPF Changing image path and show the new image in Runtime
body: <p>I have WPF Image, the source of it is local image URI on my Hard Disk, and I'm using converter to load it.</p>
  
  <p>I want to alter the image on the hard disk ( replace it with another one )
  and in <strong>runtime</strong> show the new image</p>
  
  <p>Here the XAML of the image </p>
  
  <pre><code> &lt;Image  Stretch="Fill"&gt;
                                              &lt;Image.Style&gt;
                                                  &lt;Style TargetType="Image"&gt;
                                                      &lt;Setter Property="Source" Value="{Binding ImagePath,Converter={StaticResource ImageFileLoader},UpdateSourceTrigger=PropertyChanged}"/&gt;
                                                  &lt;/Style&gt;
                                              &lt;/Image.Style&gt;
                                          &lt;/Image&gt;
  </code></pre>
  
  <p>Here is the converter </p>
  
  <pre><code> class ImageFileLoader : IValueConverter
  {
      public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          if (value != null)
          {
              string filePath = value.ToString();
              if (File.Exists(filePath))
              {
                  BitmapImage result = new BitmapImage();
                  result.BeginInit();
                  result.UriSource = new Uri(filePath);
                  result.CacheOption = BitmapCacheOption.OnLoad;
                  result.EndInit();
                  return result;
              }
  
          }
  
          return null;
      }
  </code></pre>
  
  <p>}</p>
  
  <p>Note : I tried to change the <code>CacheOption</code> in the converter to <code>BitmapCacheOption.None</code> or any other option ... it did't work because in this case I cannot alter the image on the Hard disk </p>