var image = new BitmapImage();
image.ImageFailed += (s, e) => {
// ...
};
image.UriSource = new Uri("someurl", UriKind.Absolute);
在文档中提到可以通过以下方式引发ImageFailed事件:
是否有可能在事件中检测出这些条件中的哪一个?
答案 0 :(得分:1)
是的,因为event参数是ExceptionRoutedEventArgs,它具有ErrorException属性,您可以在其中检查以下异常类型:
SecurityException
FileNotFoundException
NotSupportedException
COMException
阅读详情on MSDN
示例:
var image = new BitmapImage();
image.ImageFailed += (s, e) =>
{
if (e.ErrorException is FileNotFoundException)
// File not found.
else if (e.ErrorException is NotSupportedException)
// Unknown file format decoding error after upload
else
// Really bad stuff happened!
};