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.
Unfortunately, activation email could not send to your email. Please try again.

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

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

 

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework: Product Version:
2513 08/20/2014 01/21/2016 WinRT SfDataGrid 4.5 12.1.0.43
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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.