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