How to set a default source for an Image if binding source is null?

后端 未结 8 1846
无人及你
无人及你 2021-02-05 09:00

I\'m using binding for source of an Image control.


But this ImageUri can

8条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 09:36

    You can set the ImageFailed event on your image,

    
    

    and use the following C# to load a specific image in its place.

    private void Image_ImageFailed(object sender, ExceptionRoutedEventArgs e)
    {
        ((Image)sender).Source = new BitmapImage(new Uri("/Assets/MyDefaultImage.png", UriKind.Relative));
    }
    

提交回复
热议问题