【发布时间】:2015-04-07 18:23:48
【问题描述】:
这是我的 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 会在我想显示默认图像时得到 null 或无效路径
【问题讨论】:
-
查看内部异常。不幸的是,在 WPF 应用程序的初始化过程中,几乎所有出错的地方都会显示为“XamlParseException”,因此您必须查看 InnerException 以了解实际发生的情况。
-
我可以理解到底发生了什么,这里的图像路径不包含有问题的数据,所以那个时候我想显示默认图像。如何设置默认图片?