图像失败事件在长列表选择器 - WP7 中不起作用



>我正在使用长列表选择器。我想在找不到图像时显示默认图像。

为此,我遇到了图像失败事件。当我在列表框中使用此事件时,它工作正常。

长列表选择器中的 BuT 它不起作用。

我可以知道我犯了什么错误吗?

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

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

这是我的代码。请参考这个,让我知道我犯了什么错误?? 我也尝试过FallBackValue。它也不起作用。. 如果找不到图像,还有其他方法可以加载默认图像吗?

另一种方法是将默认Image放在当前下方。加载并显示图像后,此图像将消失

最新更新