title: Preload image resources using .NET/WPF
body: <p>I want to preload my image resources when the application is starting. The images should be cached in the application memory. So I can use
  the preloaded images in my application.</p>
  
  <p>The problem, if I load a specific View with a lot of images inside,
  the application hangs a few seconds, after that the view will appear.
  The application is <a href="http://en.wikipedia.org/wiki/Extensible_Application_Markup_Language" rel="nofollow">XAML</a>-based, but the source-property of the image-controls is dynamically changed.</p>
  
  <p>I've tested a few things, but nothing seems to work.</p>
  
  <pre><code>var uri = new Uri ( "pack://application:,,,/Vibrafit.Demo;component/Resources/myImage.jpg", UriKind.RelativeOrAbsolute ); //unit.Image1Uri;
  var src = new BitmapImage ( uri );
  src.CacheOption = BitmapCacheOption.None;
  src.CreateOptions = BitmapCreateOptions.None;
  
  src.DownloadFailed += delegate {
      Console.WriteLine ( "Failed" );
  };
  
  src.DownloadProgress += delegate {
      Console.WriteLine ( "Progress" );
  };
  
  src.DownloadCompleted += delegate {
      Console.WriteLine ( "Completed" );
  };
  </code></pre>
  
  <p>but the image will not load. The only way to load the image is to show it on the screen within a Image-Control and assign the Source-Property to my newly created BitmapImage-Object. But I don't want to show all images at the startup.</p>