We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to use image path as an image source in GridImageColumn?

Platform: WinRT |
Control: SfDataGrid |
Published Date: August 20, 2014 |
Last Revised Date: January 21, 2016 |
.NET Framework: 4.5 |
Product Version: 12.1.0.43
Tags: columns, binding

GridImageColumn helps you bind the types that are supported by Image.Source,
such as BitMapImage. When you bind a format other than the supported format, such as name of the image or file path of the image, GridImageColumn does not load the images. In such cases, you can use converter in ValueBinding for GridImageColumn that converts the string path to support Image source format. The following code example illustrates how to bind the image name or file path to GridImageColumn with the help of ValueBinding along with Converter to convert image name to BitMapImage.

XAML

SfDataGrid bounded to collection of OrderInfo and OrderInfo class have a property ImageLink that contains the image names on the Project.

Following is the converter that converts image name (placed in the Project) into BitMapImage.

C#

In WinRT and UWP you can give file path directly in StringToImageConveter. Convert method code example for WinRT and UWP platform is as follows.

public object Convert(object value, Type targetType, object parameter, string language)

        {

            if (value != null)

            {

                string imagename = value as string;

                 return new Uri(string.Format(@"..\..\Image\{0}" ,

                  imagename), UriKind.Relative));

                       }

            return null;

        }

The following is the screenshot for image column that loads images in GridImage Column.

                                                                                                                

 

Sample Links:

WPF

WRT

UWP

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon