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;
}

이미지 리소스

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

적용 대상