Assalamu'alaikum。嗨,伙计们,当我将图像字节数据类型转换为 Windows Phone 中 PictureBox 上的图像时,我遇到了问题。它说“InvalidCastExpection 未处理”。
这是后面的代码:
Namespace WP7_ClientApp
Public Class ImageConverter
Implements IValueConverter
Public Function ubah(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Dim memStream As New MemoryStream(CType(value, Byte()))
memStream.Seek(0, SeekOrigin.Begin)
Dim gambar As New BitmapImage()
gambar.SetSource(memStream)
Return gambar
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
End Namespace
然后这是 XAML 代码:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox x:Name="daftar" ItemsSource="{Binding}" HorizontalAlignment="Left" Height="599" VerticalAlignment="Top" Width="456" Margin="12,10,0,0" Grid.Row="1">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<Image Height="100" Source="{Binding gambar,Converter={StaticResource ImageConverter}}" HorizontalAlignment="Left" Margin="10,10,0,0" Name="Image1" Stretch="Fill" VerticalAlignment="Top" Width="100" />
<TextBlock Margin="10" Text="{Binding id}"/>
<TextBlock Margin="10" Text="{Binding namaproduk}"/>
<TextBlock Margin="10" Text="{Binding hargaproduk}"/>
<TextBlock Margin="10" Text="{Binding keterangan}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
然后这是错误截图:http: //4.bp.blogspot.com/-qWB7oKLVE-s/UfpE0jhnhsI/AAAAAAAAABuo/2eNvw2AmTEk/s1600/Capture.PNG
任何人都可以解决这个问题?我会很高兴的,谢谢。
*注意:gambar 数据类型是具有字节数据类型的图像,我的表:http: //4.bp.blogspot.com/-2ZMzi32TXsg/UfpJ5RqRG6I/AAAAAAABu4/qe81rZm1pq0/s320/Capture.PNG