作成日: 2022/07/06 最終更新日: 2022/07/06
文書種別
使用方法
詳細
ボタン型セルに画像を表示するには、ButtonCellTypeクラスのContentTemplateプロパティに、画像を定義したDataTemplateオブジェクトを設定します。
XAMLコードで設定する場合は、以下のようになります。
◎サンプルコード(XAML)
VB/C#コードで設定する場合は、以下のようになります。
◎サンプルコード(VB)
XAMLコードで設定する場合は、以下のようになります。
◎サンプルコード(XAML)
<gss:GcSpreadSheet x:Name="GcSpreadSheet1">
<gss:GcSpreadSheet.Resources>
<DataTemplate x:Key="Button1">
<Image Source="image1.png"/>
</DataTemplate>
</gss:GcSpreadSheet.Resources>
<gss:GcSpreadSheet.Sheets>
<gss:SheetInfo RowCount="10" ColumnCount="5">
<gss:SheetInfo.Columns>
<gss:ColumnInfo>
<gss:ColumnInfo.CellType>
<gss_CellType:ButtonCellType ContentTemplate="{StaticResource Button1}" />
</gss:ColumnInfo.CellType>
</gss:ColumnInfo>
</gss:SheetInfo.Columns>
</gss:SheetInfo>
</gss:GcSpreadSheet.Sheets>
</gss:GcSpreadSheet>
VB/C#コードで設定する場合は、以下のようになります。
◎サンプルコード(VB)
Imports GrapeCity.Wpf.SpreadSheet.CellType
・・・
Dim buttonImage As DataTemplate = New DataTemplate
Dim image As FrameworkElementFactory = New FrameworkElementFactory(GetType(System.Windows.Controls.Image))
Dim bi As BitmapImage = New BitmapImage
bi.BeginInit()
bi.UriSource = New Uri("image1.png", UriKind.Relative)
bi.EndInit()
image.SetValue(System.Windows.Controls.Image.SourceProperty, bi)
buttonImage.VisualTree = image
Dim bc As ButtonCellType = New ButtonCellType
bc.ContentTemplate = buttonImage
GcSpreadSheet1.Workbook.ActiveSheet.Columns(2).CellType = bc
◎サンプルコード(C#)using GrapeCity.Wpf.SpreadSheet.CellType;
・・・
DataTemplate buttonImage = new DataTemplate();
FrameworkElementFactory image = new FrameworkElementFactory(typeof(Image));
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri("image1.png", UriKind.Relative);
bi.EndInit();
image.SetValue(Image.SourceProperty, bi);
buttonImage.VisualTree = image;
ButtonCellType bc = new ButtonCellType();
bc.ContentTemplate = buttonImage;
GcSpreadSheet1.Workbook.ActiveSheet.Columns[0].CellType = bc;