Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
350
Grid Cell Image Convertor from byte array
posted

We are trying to Display an image in one cell of our grid from an image loaded from a database.  The data access layer is returning the image column as a byte array.   The image type is png in the db.  Does someone have a sample of the xaml and the convertor code to do this?

Parents Reply
  • 20
    posted in reply to Wade Beasley

    Use sample from Infragistics help: Displaying an Image in a Field and add this:

    1. in XAML

    xmlns:local="clr-namespace:yourapplicationnamespace"

    <Grid.Resources>

    <local:ImageConverter x:Key="ImageConverter" />

    ...

    <igDP:Field Name="photo" Converter="{StaticResource ImageConverter}" >

    2. in Code behavior:

    [ValueConversion(typeof(byte[), typeof(ImageSource))]

    public class ImageConverter : IValueConverter

    {

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

    {

    if (value == null) return null;

    MemoryStream str = new MemoryStream(((byte[)value));

    BitmapImage img = new BitmapImage();

    img.BeginInit();

    img.StreamSource = str;

    img.EndInit();

    return img;

    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

    {

    return null;

    }

    }

Children