我有大量的图像(10000 +)我知道所有这些都是JPEGS(来自FF D8的文件头)
基本上我搜索一个数据库,它为我提供匹配的搜索文件名。然后我想在列表视图中显示这些图像。
我的问题是没有图片有扩展名,当我尝试将图片加载到列表视图中时,我收到以下错误:
No imaging component suitable to complete this operation was found
我相信这是因为它无法确定要打开它的文件类型。
我正在尝试使用值转换器绑定到path属性以返回将在列表视图Image控件中显示的BitmapImage。
转换器在这里:
public class PathToImageSourceConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (File.Exists(value.ToString()))
{
//these files are JPEGs but without an extension
return new BitmapImage(new Uri(value.ToString()));
}
else return new BitmapImage();
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
XAML中的WPF控件位于:
<!-- The list view containing the images, bound to the logos collection in the background -->
<ListView x:Name="lstImages"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ItemsSource="{Binding Shoeprints}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
SelectedIndex="{Binding SelectedImageIndex}">
<!-- Use a wrap panel so that the images appear side by side instead of one in each row -->
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<!-- Sets the template for the data to be displayed -->
<ListView.ItemTemplate>
<DataTemplate>
<!-- Defines the actual image being displayed -->
<Image Width="50"
Height="50"
Margin="5"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Source="{Binding ShoePrintImagePath, Converter={StaticResource PathToImageSourceConverter}}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
和ShoePrintImagePath是ShoePrints类中的字符串属性。我知道其余的工作正如我在这个列表中成功绑定到这个类中的其他属性但我无法将其用于图像。
C# VS 2012 WPF XAML