This is a migrated thread and some comments may be shown as answers.

Binding Image from SQL

1 Answer 61 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Albert
Top achievements
Rank 1
Albert asked on 10 Jan 2011, 04:17 PM
hi telerik Team,

I've got a hierarchical treeview and would like to display some images on the nodes.
I've got a imageconverter:

public

 

 

class ImageConverter : IValueConverter

 

{

 

 

public static object ByteToBitmap(byte[] byteImg)

 

{

 

 

using (MemoryStream ms = new MemoryStream(byteImg, 0, byteImg.Length))

 

{

 

 

//Convert byte[] to image

 

 

 

Image image = new Image();

 

 

 

BitmapImage bitmapimage = new BitmapImage();

 

 

 

MemoryStream stream = new MemoryStream(byteImg);

 

bitmapimage.SetSource(stream);

 

 

return bitmapimage;

 

}

}

 

 

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

 

{

 

 

byte[] byteImg = (byte[])value;

 

 

 

//Convert byte to image

 

 

 

return ByteToBitmap(byteImg);

 

}

Part of the xaml file:
<telerik:HierarchicalDataTemplate x:Key="CustomerTemplate" ItemsSource="{Binding Teams}" ItemTemplate="{StaticResource OrderTemplate}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="DayID: "/>
<TextBlock Text="{Binding Date}"/>
<Image Source="{Binding Image, Converter={StaticResource ImageConverter}}" />
</StackPanel>
</telerik:HierarchicalDataTemplate>

 

 

 

 

The images are stored as "Image" in the SQL database.

I get an object reference on the following line of code:
using (MemoryStream ms = new MemoryStream(byteImg, 0, byteImg.Length))

 

I can't find a solution to retrieve and bind the images that are stored in my database.
Any help would be appreciated!

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Petar Mladenov
Telerik team
answered on 13 Jan 2011, 02:59 PM
Hello Albert,

Please find the solution I prepared for you. Basically it uses Ado.Net entity data model and retrieves Employees photo from the MS SQL Express NorthWind database. The solution is based on this article although the project in it uses WCF Ria services.
Check it out and let us know if it gives you a starting point or if it doesn`t help you, it would be best if you can send us your code so that we could investigate in depth.

All the best,
Petar Mladenov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
TreeView
Asked by
Albert
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or