1

我有一个带有数据模板的列表框。问题是它期望源是一个字符串。我拥有的字符串是 xap 文件中图像的 uri。所以它将是 uri(xxx, uri.relative) 由于我只能使用字符串值,我如何让它在 xap 文件中查看图像?

ListBox.ItemTemplate  
DataTemplate  
StackPanel Orientation=Horizontal VerticalAlignment=Center

Image Source="{Binding Path=Image}" Width="50" Height="50" Margin="0,0,10,0"  
StackPanel 
DataTemplate  
ListBox.ItemTemplate

//it won't let me use URI for the Image return value!!!

public class MyListboxItem

{

public String Image

{

get { return thumb; 

}

}
4

1 回答 1

1

它使用图像源......但它会为您重新将字符串转换为图像源。所以我只需要创建一个位图并发送它......并以一种肮脏的方式创建一个位图。

公共 ImageSource Image { get {
StreamResourceInfo rs = App.GetResourceStream(new Uri( thumb, UriKind.Relative));

           if (rs == null)
              return new BitmapImage();

           BitmapImage bitmapPreview = new BitmapImage();
           bitmapPreview.SetSource(rs.Stream);
           return bitmapPreview; 
        }
    }
于 2009-07-15T21:20:57.860 回答