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!