简体   繁体   中英

ImageFailed event did not work in long list selector - WP7

I am using long list selector. I want to show default image when image is not found.

for that I am having ImageFailed event. When I use this event in list box it worked fine.

BuT in long list selector it's not working.

May I know what mistake I did??

<DataTemplate x:Key="ItemTemplate" >
        <StackPanel Orientation="Horizontal">
            <Image Source="{Binding ListImage}" Height="100" Width="100" Stretch="Uniform" Margin="10,2,0,0" ImageFailed="Image_ImageFailed" />
            <TextBlock Text="{Binding ListFullName}" Width="200" Foreground="Black" Margin="10,10,0,0" FontWeight="SemiBold" FontSize="22" />
            <TextBlock Text="{Binding ListBio}" FlowDirection="LeftToRight" Foreground="Black" Margin="-200,50,0,0" FontWeight="ExtraLight" FontSize="20" />
        </StackPanel>
    </DataTemplate>

Image Failed event in CS:-

private void Image_ImageFailed(object sender, ExceptionRoutedEventArgs e)
    {
        MessageBox.Show(e.ErrorException.Message);
        Image Img = (Image)sender;
        Img.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Test;component/Images/Head@2x.png", UriKind.Relative));

    }

This is my code. Please refer this and let me know what mistake I did?? And also I have tried FallBackValue. It is also Not working.. Is there any other way to load the default image if the image not found??

Another approach is to place default Image below the your current one. This image will disappear after your image has been loaded and displayed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM