アッサラームアライクム。こんにちは、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/AAAAAAAABuo/2eNvw2AmTEk/s1600/Capture.PNG
誰でもこれを解決できますか?とても嬉しいです、ありがとう。
*注: ガンバーのデータ型はバイト データ型のイメージです。