C1FlexGrid如何改变第一行的样式
Hi C1朋友,我现有个需求是将C1FlexGrid第一行的字体加粗。我的做法是加了LoadedRows事件,
if (AnalysisFlexgridDataGrid != null && AnalysisFlexgridDataGrid.Rows != null && AnalysisFlexgridDataGrid.Rows.Count > 0)
{
AnalysisFlexgridDataGrid.Rows.FontWeight = FontWeights.Bold;
}
第一次Loaded完FlexGrid第一行的字体有改变, 如果FlexGrid的itemSource改变,C1FlexGrid能正确显示改变后的Source。 但是它的Rows.Count == 0. 就无法改变第一行的字体。
请问有什么其他办法?
多谢多谢! 回复 1楼jxlxl的帖子
可以使用CellFactory来实现。
包含斜体、贯穿线和粗体,代码参考:
public class MyCellFactory : C1.WPF.FlexGrid.CellFactory
{
public override void ApplyCellStyles(C1.WPF.FlexGrid.C1FlexGrid grid, C1.WPF.FlexGrid.CellType cellType, C1.WPF.FlexGrid.CellRange rng, Border bdr)
{
base.ApplyCellStyles(grid, cellType, rng, bdr);
if (cellType == C1.WPF.FlexGrid.CellType.Cell)
{
var row = grid.Rows.Index;
var _textblock = bdr.Child as TextBlock;
if (row % 2 == 0)
{
//underline text
_textblock.FontWeight = FontWeights.Bold;
_textblock.FontStyle = FontStyles.Italic;
_textblock.TextDecorations = TextDecorations.Strikethrough;
}
else
{
//Strikeout text
bdr.Child = null;
double width = 0;
double height = 0;
if (_textblock != null)
{
width = _textblock.ActualWidth;
height = _textblock.ActualHeight;
}
Line _line = new Line();
_line.Stroke = new SolidColorBrush(Colors.Black);
_line.StrokeThickness = 1;
_line.X1 = 0;
_line.Y1 = (height / 2) + 3;
_line.X2 = width + 1;
_line.Y2 = (height / 2) + 3;
Grid grd = new Grid();
grd.Children.Add(_line);
_textblock.FontWeight = FontWeights.Thin;
_textblock.FontStyle = FontStyles.Italic;
grd.Children.Add(_textblock);
bdr.Child = grd;
}
}
}
}
public class TestData
{
public string Name { get; set; }
public string Title { get; set; }
}
安装产品后,也可以在如下路径找到CellFactory示例演示:
\Documents\ComponentOne Samples\Studio for WPF\C1.WPF.FlexGrid\CS\UnboundCellFactory
页:
[1]