[]
        
(Showing Draft Content)

イメージ型セル

イメージ型セルはセルに画像を表示します。ImageCellType クラスを使用して設定します。

!type=note

メモ:デザイナを使用した設定方法については、「イメージ型セルの設定」をご覧ください。

イメージ型セル

主な設定は次のとおりです。

セルの値の ImageSource への変換

イメージ型セルの値は画像のソースを表す ImageSource または画像を表すバイナリ データであることが求められます。たとえば、セルの値がイメージ ファイルへのパスを表す文字列である場合があります。このようにセルの値が ImageSource 型、または画像を表すバイナリ データでない場合、値を ImageSource に変換する ImageConverter を設定することで対応できます。

ImageConverter は IImageSourceConverter インタフェースを実装して作成します。

次のサンプルコードはアプリケーションの img フォルダーに保存された SpreadPicture.png ファイルをイメージ型セルに読み込みます。SpreadFilePathToImageConverter クラスが、ファイル パスを BitmapImage に変換します。

サンプルコード

ImageCellType img = new ImageCellType();
img.ImageConverter = new SpreadFilePathToImageConverter();
gcSpreadGrid1[0, 3].CellType = img;
gcSpreadGrid1[0, 3].Value = "img/SpreadPicture.png";
public class SpreadFilePathToImageConverter : IImageSourceConverter
{
    public ImageSource GetImageSource(object value)
    {
        if (value != null)
        {
            BitmapImage bmi = new BitmapImage(new Uri(value.ToString(), UriKind.Relative));
            return bmi;
        }
        else return null;
    }
}
Dim img As New ImageCellType()
img.ImageConverter = New SpreadFilePathToImageConverter()
GcSpreadGrid1(0, 3).CellType = img
GcSpreadGrid1(0, 3).Value = "img/SpreadPicture.png"
Public Class SpreadFilePathToImageConverter
    Implements IImageSourceConverter
    Public Function GetImageSource(value As Object) As ImageSource Implements IImageSourceConverter.GetImageSource
        If value IsNot Nothing Then
            Dim bmi As New BitmapImage(New Uri(value.ToString(), UriKind.Relative))
            Return bmi
        Else
            Return Nothing
        End If
    End Function
End Class

画像の引き延ばし

Stretch プロパティで設定します。

関連トピック

セル型

セル型の設定

セル型とセルの値

セル型と編集用コントロール

セル型とイベント

標準型セル

テキスト型セル

日付時刻型セル

数値型セル

マスク型セル

コンボボックス型セル

ボタン型セル

チェックボックス型セル

ラジオグループ型セル

データテンプレート型セル