作成日: 2013/06/25 最終更新日: 2014/03/19
文書種別
使用方法
詳細
セル単位でセルの背景色や前景色を変更するには、CellFactoryを継承するクラスを作成してApplyCellStylesメソッドをオーバーライドし、Borderの背景色と、Borderの子のTextBlockの前景色を設定します。
◎サンプルコード(Visual Basic)
◎サンプルコード(C#)
◎サンプルコード(Visual Basic)
Imports C1.WPF.FlexGrid
Public Sub New()
:
C1FlexGrid1.CellFactory = New MyCellFactory
End Sub
Public Class MyCellFactory
Inherits CellFactory
Public Overrides Sub ApplyCellStyles(grid As C1FlexGrid, cellType As CellType, rng As CellRange, bdr As Border)
MyBase.ApplyCellStyles(grid, cellType, rng, bdr)
If cellType = C1.Silverlight.FlexGrid.CellType.Cell Then
If rng.Column = 1 AndAlso rng.Row = 1 Then
' セルの背景色と前景色を変更します。
bdr.Background = New SolidColorBrush(Colors.Red)
Dim tb As TextBlock = bdr.Child
If tb IsNot Nothing Then
tb.Foreground = New SolidColorBrush(Colors.White)
End If
End If
End If
End Sub
End Class
Public Sub New()
:
C1FlexGrid1.CellFactory = New MyCellFactory
End Sub
Public Class MyCellFactory
Inherits CellFactory
Public Overrides Sub ApplyCellStyles(grid As C1FlexGrid, cellType As CellType, rng As CellRange, bdr As Border)
MyBase.ApplyCellStyles(grid, cellType, rng, bdr)
If cellType = C1.Silverlight.FlexGrid.CellType.Cell Then
If rng.Column = 1 AndAlso rng.Row = 1 Then
' セルの背景色と前景色を変更します。
bdr.Background = New SolidColorBrush(Colors.Red)
Dim tb As TextBlock = bdr.Child
If tb IsNot Nothing Then
tb.Foreground = New SolidColorBrush(Colors.White)
End If
End If
End If
End Sub
End Class
◎サンプルコード(C#)
using C1.WPF.FlexGrid;
public MainPage()
{
:
c1FlexGrid1.CellFactory = new MyCellFactory();
}
public class MyCellFactory : CellFactory
{
public override void ApplyCellStyles(C1FlexGrid grid, CellType cellType, CellRange rng, Border bdr)
{
base.ApplyCellStyles(grid, cellType, rng, bdr);
if (cellType == CellType.Cell)
{
if (rng.Column == 1 && rng.Row == 1)
{
// セルの背景色と前景色を変更します。
bdr.Background = new SolidColorBrush(Colors.Red);
var tb = bdr.Child as TextBlock;
if (tb != null)
{
tb.Foreground = new SolidColorBrush(Colors.White);
}
}
}
}
}
public MainPage()
{
:
c1FlexGrid1.CellFactory = new MyCellFactory();
}
public class MyCellFactory : CellFactory
{
public override void ApplyCellStyles(C1FlexGrid grid, CellType cellType, CellRange rng, Border bdr)
{
base.ApplyCellStyles(grid, cellType, rng, bdr);
if (cellType == CellType.Cell)
{
if (rng.Column == 1 && rng.Row == 1)
{
// セルの背景色と前景色を変更します。
bdr.Background = new SolidColorBrush(Colors.Red);
var tb = bdr.Child as TextBlock;
if (tb != null)
{
tb.Foreground = new SolidColorBrush(Colors.White);
}
}
}
}
}
旧文書番号
80195