作成日: 2022/07/06 最終更新日: 2022/07/06
文書種別
使用方法
詳細
ボタン型セルに画像を表示するには、ButtonCellTypeクラスのContentTemplateプロパティに、画像を定義したDataTemplateオブジェクトを設定します。
XAMLコードで設定する場合は、以下のようになります。
◎サンプルコード(XAML)
VB/C#コードで設定する場合は、以下のようになります。
◎サンプルコード(VB)
XAMLコードで設定する場合は、以下のようになります。
◎サンプルコード(XAML)
<sg:GcSpreadGrid x:Name="gcSpreadGrid1">
<sg:GcSpreadGrid.Resources>
<DataTemplate x:Key="Button1">
<Image Source="image1.png"/>
</DataTemplate>
</sg:GcSpreadGrid.Resources>
<sg:GcSpreadGrid.Columns>
<sg:Column>
<sg:Column.CellType>
<sg:ButtonCellType ContentTemplate="{StaticResource Button1}"/>
</sg:Column.CellType>
</sg:Column>
</sg:GcSpreadGrid.Columns>
</sg:GcSpreadGrid>
VB/C#コードで設定する場合は、以下のようになります。
◎サンプルコード(VB)
Imports GrapeCity.Windows.SpreadGrid
Class MainWindow
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
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
gcSpreadGrid1.Columns(2).CellType = bc
End Sub
End Class
◎サンプルコード(C#)using GrapeCity.Windows.SpreadGrid;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
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;
gcSpreadGrid1.Columns[0].CellType = bc;
}
}