以下是我的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获得空路径或无效路径时,我希望显示默认图像
发布于 2019-05-24 12:41:50
BitmapImage throws an initialization exception when file does not exist
这个答案对我有效,也适用于你遇到的同样的问题。如果图像文件丢失,我可以使用转换器返回我想要的图像。
https://stackoverflow.com/questions/29498515
复制相似问题