Image cells display an image as data within a cell.
To create an image in a cell, use the ImageCellType class in the GrapeCity.Wpf.SpreadSheet.CellType namespace.
The value of an image cell should be an ImageSource representing the source of an image or binary data that represents an image. For example, the cell value may be a string that specifies the path to an image file. If the cell value is not an ImageSource type or binary data, which represents an image, you can set an ImageConverter to convert the value into an ImageSource. To create an ImageConverter, use the IImageSourceConverter interface.
There are two ways to set up an image cell in a spreadsheet.
Using XAML view
The following example code sets up an image cell in XAML and then defines the image path in code.
XAML |
Copy Code
|
---|---|
<Window.Resources> <local:SpreadFilePathToImageConverter x:Key ="MyImageConverter"/> </Window.Resources> <Grid> <gss:GcSpreadSheet x:Name ="spreadSheet1" HorizontalAlignment ="Stretch" VerticalAlignment ="Stretch" > <gss:GcSpreadSheet.Sheets> <gss:SheetInfo ColumnCount ="20" RowCount ="50"> <gss:SheetInfo.Columns > <gss:ColumnInfo Width ="250"> <gss:ColumnInfo.CellType> <CT:ImageCellType Stretch ="Fill" ImageConverter ="{StaticResource MyImageConverter}"/> </gss:ColumnInfo.CellType> </gss:ColumnInfo> </gss:SheetInfo.Columns> </gss:SheetInfo > </gss:GcSpreadSheet.Sheets> </gss:GcSpreadSheet> </Grid> |
Using Code view
The following code loads the "picture.png" file from the D drive of the application into an image cell, C2. Here, the SpreadFilePathToImageConverter class converts the file path into a BitmapImage.