0
我在我的WPF项目中设置了“MyObjectCollection”数据源的ListBox。 我已经设法让ListBox显示我的集合,并且每个项目都显示对象的两个字符串属性。该对象还包含一个图像,我如何让图像显示在列表框中?将XAML中的WPF图像设置为属性
我目前使用下面的代码绑定到我的数据源
<UserControl.Resources>
<DataTemplate x:Key="CustomerTemplate">
<Border BorderThickness="2" BorderBrush="silver" CornerRadius="5" Padding="1"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid>
<Image Source="{Binding Artwork}" Tag="{Binding Artwork}" VerticalAlignment="Stretch" ></Image>
<TextBlock Text="{Binding Name}" Foreground="#515151"
FontSize="16" HorizontalAlignment="Stretch"
FontWeight="Bold" />
<TextBlock Text="{Binding Length}" Foreground="#515151" Margin="0,25,0,0"
FontSize="10" HorizontalAlignment="Stretch"
FontWeight="Bold" />
</Grid>
</Border>
</DataTemplate>
</UserControl.Resources>
感谢, 本
Image控件期望源是一个URI,而不是实际的图像...你能告诉我们什么样的“作品”是什么? – Brent 2010-04-26 21:26:57
图形是一个System.Drawing.Image类型 – Ben 2010-04-27 07:10:17
'System.Drawing.Image'是WindowsForms while ['System.Windows.Media.ImageSource'](http://msdn.microsoft.com/en-us/library/system .windows.media.imagesource.aspx)是应该在WPF中使用的类型。正如布伦特所指出的,最简单的方法是使用'Uri'。 – gehho 2010-04-27 07:16:54