title: How to check if BitmapImage created by Uri is actually an image?
body: <p>my application receives dragged and dropped links from Internet and tries to create image from supplied link.</p>
  
  <p>Code looks like this.</p>
  
  <pre><code>if (link.StartsWith("http"))
  {
      try
      {
          itemImage.Source = new BitmapImage(new Uri(link));
          if (itemImage.Source != null)
          {
              if (itemImage.Visibility == Visibility.Collapsed)
                  ShowImage();
          }
      }
      catch (Exception){}
  }
  </code></pre>
  
  <p>It handles it's job quite well to the moment when provided link contain path to image.
  If path is for example "<a href="https://stackoverflow.com/">https://stackoverflow.com/</a>" program assumes that this link provides image too, so it's running code inside of if condition (imageSource != null) and shows empty image. </p>
  
  <p>However while pressing button to save that invalid "image" and checking if Source isn't really null program runs ShowNameError method (with assumption that name is set properly)</p>
  
  <pre><code>if (itemImage.Source == null || name == string.Empty)
  {
      ShowNameError("Set name or/and image of item first");
      return;
  }
  </code></pre>
  
  <p>In other words - ImageSource isn't null in first condition, but in second it is null, which doesn't make sense because nowhere in code ImageSource is manipulated anymore.</p>
  
  <p>And since that magic tricks are happening, I'm asking you how to check if BitmapImage created by Uri IS actually an image?</p>