Image.ImageFailed 이벤트

정의

이미지 검색 또는 형식과 관련된 오류가 있을 때 발생합니다.

public:
 virtual event ExceptionRoutedEventHandler ^ ImageFailed;
// Register
event_token ImageFailed(ExceptionRoutedEventHandler const& handler) const;

// Revoke with event_token
void ImageFailed(event_token const* cookie) const;

// Revoke with event_revoker
Image::ImageFailed_revoker ImageFailed(auto_revoke_t, ExceptionRoutedEventHandler const& handler) const;
public event ExceptionRoutedEventHandler ImageFailed;
function onImageFailed(eventArgs) { /* Your code */ }
image.addEventListener("imagefailed", onImageFailed);
image.removeEventListener("imagefailed", onImageFailed);
- or -
image.onimagefailed = onImageFailed;
Public Custom Event ImageFailed As ExceptionRoutedEventHandler 
<Image ImageFailed="eventhandler"/>

이벤트 유형

설명

이 이벤트가 발생할 수 있는 조건은 다음과 같습니다.

  • 파일을 찾을 수 없습니다.
  • 잘못된 파일 형식(인식할 수 없거나 지원되지 않음)
  • 업로드 후 알 수 없는 파일 형식 디코딩 오류
  • 시스템에 의해 정규화된 리소스 다시 로드 오류의 특성을 확인하기 위해 이벤트 데이터에서 ErrorMessage 를 사용할 수 있습니다.

ImageFailed 및 ImageOpened 은 상호 배타적입니다. 이미지원본 값이 설정되거나 다시 설정될 때마다 한 이벤트 또는 다른 이벤트가 항상 발생합니다.

ImageFailed를 처리하는 한 가지 시나리오는 기본 BitmapImage 원본의 UriSource를 다른 로컬 이미지 파일로 설정하는 것입니다. 이 값은 빈 공간 대신 표시할 대체 값으로 사용될 수 있습니다. 예를 들어 원본이 더 이상 없을 수 있는 외부 이미지를 표시하거나 사용자가 인터넷에 연결되어 있지 않은 경우 앱 패키지의 일부이며 항상 사용할 수 있도록 보장되는 로컬 대체 또는 자리 표시자 이미지를 참조하도록 UriSource 를 설정할 수 있습니다.

Image 요소가 라이브 시각적 트리에 없는 경우 Image 요소는 ImageOpened 또는 ImageFailed 이벤트를 발생시키지 않습니다. 요소가 라이브 트리에 없는 동안 이러한 이벤트를 수신해야 하는 경우 BitmapImage를 사용합니다. ImageOpened/ImageFailed 이벤트.

private void Image_ImageFailed(object sender, ExceptionRoutedEventArgs e) {
    Image img = sender as Image;
    BitmapImage fallbackImage = new BitmapImage(new Uri("ms-appx:///Images/fallback.png"));
    img.Width = 100; //set to known width of this source's natural size
     //might instead want image to stretch to fill, depends on scenario
    img.Source = fallbackImage;
}

Windows 8 동작

Windows 8의 경우 리소스는 리소스 한정자 패턴을 사용하여 디바이스별 크기 조정에 따라 다른 리소스를 로드할 수 있습니다. 그러나 앱이 실행되는 동안 크기 조정 요소가 변경되면 리소스가 자동으로 다시 로드되지 않습니다. 이 경우 앱은 DpiChanged 이벤트(또는 사용되지 않는 LogicalDpiChanged 이벤트)를 처리하고 ResourceManager API를 사용하여 새 크기 조정 요소에 적합한 리소스를 수동으로 다시 로드하여 리소스 다시 로드를 처리해야 합니다. Windows 8.1 시작해서 앱이 실행되는 동안 크기 조정 요소가 변경되면 앱에 대해 원래 검색된 모든 리소스가 자동으로 다시 평가됩니다. 또한 해당 리소스가 Image 개체의 이미지 원본인 경우 시스템에서 새 리소스를 요청한 다음 이미지에 적용한 결과로 소스 로드 이벤트(ImageOpened 또는 ImageFailed) 중 하나가 발생합니다. 런타임 규모 변경이 발생할 수 있는 시나리오는 사용자가 둘 이상의 모니터를 사용할 수 있을 때 앱을 다른 모니터로 이동하는 경우입니다.

Windows 8에서 Windows 8.1 앱 코드를 마이그레이션하는 경우 XAML에서 원본이 설정된 경우에도 크기 변경이 처리될 때 런타임에 발생하는 ImageOpened 또는 ImageFailed 이벤트가 발생하므로 이 동작 변경에 대해 고려할 수 있습니다. 또한 DpiChangedLogicalDpiChanged/를 처리하고 리소스를 다시 설정하는 코드가 있는 경우 새 Windows 8.1 자동 다시 로드 동작을 고려할 때 해당 코드가 여전히 필요한지 확인해야 합니다.

Windows 8용으로 컴파일되었지만 Windows 8.1에서 실행하는 앱은 Windows 8 동작을 계속 사용합니다.

적용 대상