嘿。 我有一個用戶可以搜索的項目列表。搜索結果顯示在列表框中。每個「animal
」對象都有一個指向「隔離存儲」中圖像的路徑。將listboxitem中的Image控件綁定到獨立存儲中的圖像的最快捷方式是什麼?我見過的例子傾向於從互聯網上顯示圖像,而不是孤立存儲。如果我有大約10張圖像,它似乎佔用了所有的內存和崩潰。感謝孤立存儲中的綁定圖像
編輯:
我在我的BitmapConverter
類使用這個(繼承的IValueConverter)
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value !=null)
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(new MemoryStream((Byte[]) value));
return bitmapImage;
}
else
{
return null;
}
}
我有這個在我AppResource.xaml文件的頂部:
<ImageApp_Converter:BitmapConverter x:Key="bmpConverter" />
In my style, within the AppResource.xaml file:
<Image HorizontalAlignment="Left" Margin="8,8,0,4" Width="160" Height="120" Source="{Binding Converter={StaticResource bmpConverter}}" />
我在我的BitmapConverter中設置了一個斷點,但它從來沒有被調用過。我從來沒有使用過IValueConverter,所以任何幫助都會很棒。謝謝
您是否忘記了綁定中的路徑?如果綁定到DataContext(而不是綁定到它的路徑),則應該通過{Binding。,Converter = {...}}或{Binding Path =。,Converter = {...}}來提及 – 2010-11-08 14:29:03