title: How to cast a Window's icon to BitmapImage
body: <p>I'm trying thx to the help of this thread <a href="https://stackoverflow.com/questions/920517/convert-imagesource-to-bitmapimage-wpf">Convert ImageSource to BitmapImage - WPF</a> to convert my Window's <code>icon</code> which is of type <code>ImageSource</code> to <code>BitmapImage</code> : </p>
  
  <pre><code>var bi = _window.Icon as BitmapImage;
  </code></pre>
  
  <p>The problem is that the cast is not happening (bi is null after executing this line) and I'm sure that the <code>_window.Icon</code> is not null, can any one tell me why this conversion is not happening ?</p>
  
  <p><strong>Update :</strong></p>
  
  <p>Although the Visual Studio documentation says that the Window.Icon is of tyme <code>ImageSource</code> but the debugger is saying that it's a <code>System.Windows.Media.Imaging.BitmapFrameDecode</code></p>
  
  <p>When doing :</p>
  
  <pre><code>var bi = (BitmapImage) _window.Icon;
  </code></pre>
  
  <p>I get the following exception:</p>
  
  <blockquote>
    <p>Additional information: Unable to cast object of type
    'System.Windows.Media.Imaging.BitmapFrameDecode' to type
    'System.Windows.Media.Imaging.BitmapImage'.</p>
  </blockquote>