Public classBinarytoimageconverter:ivalueconverter { Public ObjectConvert (ObjectValue, Type TargetType,Objectparameter, CultureInfo culture) { if(Value isBinary) { byte[] bytes =New byte[(Value asBinary). Bytes.length]; Bytes= (value asBinary). Bytes; MemoryStream Stream=NewMemoryStream (Bytes,0, Bytes. Length); BitmapImage Image=NewBitmapImage (); Try{image. SetSource (stream); returnimage; } Catch(Exception ex) {MessageBox.Show (ex). ToString ()); } } if(Value isString) { strings =value. ToString (); returnS +1111; } return NULL; } Public ObjectConvertback (ObjectValue, Type TargetType,Objectparameter, CultureInfo culture) { Throw Newnotimplementedexception (); } }
<grid x:name="LayoutRoot"Background=" White"> <Grid.Resources> <silverlightapplication2:binarytoimageconverter x:key="Binaryconventer"></silverlightApplication2:BinaryToImageConverter> </Grid.Resources> <StackPanel> <button x:name="Btselectfile"height=" -"Content="Select File"click="Btselectfile_click"></Button> <button x:name="Btshow"height=" -"Content="Show Pictures"click="Btupload_click"></Button> <listbox x:name="ListBox"height="260"Selectionchanged="listbox_selectionchanged"> <ListBox.ItemTemplate> <DataTemplate> <STACKP Anel orientation="Vertical"> <textblock height=" -"text="{Binding Productenname,converter={staticresource binaryconventer}}"Width=" -"></TextBlock> <image x:name="Image"height=" -"Width=" -"Source="{Binding imagebinary, Converter={staticresource binaryconventer}}"></Image> <!--<image x:name="Image"height=" -"Width=" -"Source="{Binding Productenname}"></Image>--> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </StackPanel> </Grid>
Save the picture to the database, and load the picture