Wpf 位图图像异常

Wpf 位图图像异常,wpf,xaml,Wpf,Xaml,以下是我的XAML代码: <Image Stretch="Fill" Margin="15,0,0,0" ToolTip="{Binding ImagePath}" Width="110" Height="100" > <Image.Source> <BitmapImage RenderOptions.BitmapScalingMode="LowQuality" CacheOption="OnLoad" DecodePixelWidth="200" Cre

以下是我的XAML代码:

<Image Stretch="Fill" Margin="15,0,0,0" ToolTip="{Binding ImagePath}" Width="110" Height="100" >
  <Image.Source>
   <BitmapImage RenderOptions.BitmapScalingMode="LowQuality" CacheOption="OnLoad" DecodePixelWidth="200" CreateOptions="IgnoreColorProfile" UriSource="{Binding ImagePath ,FallbackValue={StaticResource Lost},TargetNullValue={StaticResource Lost}}"/>
  </Image.Source>
</Image>

这给了我一个错误:

类型的未处理异常 中出现“System.Windows.Markup.XamlParseException” PresentationFramework.dll

其他信息:初始化 “System.Windows.Media.Imaging.BitmapImage”引发异常

有时UriSource获取空路径或无效路径,此时我希望显示默认图像


这个答案对我很有用,和你遇到的问题一样。如果图像文件丢失,我可以使用转换器返回所需的图像。

查看内部异常。不幸的是,在WPF应用程序初始化过程中出现的几乎所有错误都显示为“XamlParseException”,因此您必须查看InnerException以了解实际发生的情况。我可以理解实际发生的情况,这里的图像路径不包含有问题的数据,所以此时我希望显示默认图像。如何设置默认图像?