【问题标题】:BitmapImage exception位图图像异常
【发布时间】: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 以了解实际发生的情况。
  • 我可以理解到底发生了什么,这里的图像路径不包含有问题的数据,所以那个时候我想显示默认图像。如何设置默认图片?

标签: wpf xaml


【解决方案1】:

BitmapImage throws an initialization exception when file does not exist

这个答案对我有用,对于你遇到的同样的问题。如果图像文件丢失,我可以使用转换器返回我想要的图像。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-09
    • 2012-11-24
    • 2012-01-27
    • 1970-01-01
    • 2014-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多