WPF ComponentOneFlexGrid设置样式技巧:(三)设置选择单元格颜色和字体
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
WPF ComponentOneFlexGrid设置样式技巧:(三)设
置选择单元格颜色和字体
除了使用ApplyCellStyles方法,通过CreateCellContent方法,我们也可以实现单元格设置颜色和样式的效果。
本文就在此基础上讨论如何可以设置选择单元格的样式。
CreateCellContent方法设置单元格样式代码参考:
效果:
了解了这些知识,我们就可以运用这些知识设置选择的样式。
选择的前景色,背景色可以通过SelectionBackground和SelectionForeground直接设置。
其他字体样式依然可以通过继承MyCellFactory的方法实现(CreateCellContent或是ApplyCellStyle)实现。
在方法里添加选择的判断,当选择的时候改变选择的样式,代码参考:
public override void CreateCellContent(C1FlexGrid grid, Borde r bdr, CellRange rng)
{
base.CreateCellContent(grid, bdr, rng);
var columnindex = rng.Column;
var rowindex = rng.Row;
var tb = bdr.Child as TextBlock;
bool selected = (columnindex == grid.Selection.Col umn && rowindex == grid.Selection.Row);
if (tb != null && selected)
{
ContentPresenter cp = (VisualTreeHelper.GetPar ent(tb) as ContentPresenter);
System.Windows.Media.RotateTransform rotateTra nsform = new RotateTransform();
rotateTransform.Angle = 50;
youtTransform = rotateTransform;
tb.FontWeight = FontWeights.Bold;
tb.FontSize = 14;
}
}
注意在SelectionChanged事件调用下刷新:
效果如图: