How to Show Images in a Silverlight Datagrid

Written by steve mcdonnell Google
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Show Images in a Silverlight Datagrid
Display an image in a Microsoft Silverlight grid. (digital image by Clark Duffy from Fotolia.com)

It's easy to display an image in a Microsoft Silverlight data grid. Instead of using "DataGridTextColumn" to display data in a column, use "DataGridTemplateColumn" to create a data template for the column. In the data template, create an image object and specify the image, width and height to display the image in the cell.

Skill level:
Easy

Other People Are Reading

Instructions

  1. 1

    Create the data grid by dragging the DataGrid control from the toolbox and dropping it in your project. Set the "AutoGenerateColumns" property to "False," "Read Only" to "True," "Sort Columns" to "True" and set an appropriate margin.

  2. 2

    Create a handler to retrieve the text and images, bind them and serve them to the data grid. Create an error routine specific to the images in case there is a problem displaying an image.

  3. 3

    Add the image column using "DataGridTempalteColumn." Add a cell template and create an image object to display the image in the cell. For example:

    <data:DataGridTemplateColumn>
    
            <data:DataGridTemplateColumn.CellTemplate>
    
                <DataTemplate>
    
                        <Image x:Name="picture" ImageFailed="picture_ImageFailed" Width="200" Height="130" Visibility="Visible"/>
    
                </DataTemplate>
    
            </data:DataGridTemplateColumn.CellTemplate>
    
        </data:DataGridTemplateColumn>
    

Tips and warnings

  • Microsoft Silverlight does not support displaying bitmap images. To display a bitmap image in a Silverlight grid, you have to convert it to .jpg format.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.