使用表格控件,经常会使用到旋转文字角度的功能。使用 C1FlexGrid 控件,实现文本旋转是十分容易的,本章将阐述合并单元格旋转文字的实现方法。
选择合并单元格中的文本
首先,需要继承 CellFactory 创建自定义类。
public class myCellfactory : CellFactory{}
然后,需要重载 http://helpcentral.componentone.com/nethelp/c1flexgridwpf/#!XMLDocuments/FlexgridWPFRef/html/M_C1_WPF_FlexGrid_CellFactory_CreateCellContent_3_e6bfeaa3.htm 方法,设置 RotateTransform 角度 ,链接为 RotateTransform 类的详细说明。
public class myCellfactory : CellFactory{public override void CreateCellContent(C1FlexGrid grid, Border bdr, CellRange rng){base.CreateCellContent(grid, bdr, rng);
var tb = bdr.Child as TextBlock;
if (tb != null && rng.Column == 2 || rng.Column == 7 || rng.Column == 8){ContentPresenter cp = (VisualTreeHelper.GetParent(tb) as ContentPresenter);
System.Windows.Media.RotateTransform rotateTransform = new RotateTransform();
rotateTransform.Angle = 50;tb.LayoutTransform = rotateTransform;bdr.Background = Brushes.PaleGreen;tb.Foreground = Brushes.Blue;}}}
把自定义的 CellFactory 对象赋值给 C1FlexGrid,效果图如下:
更详细设置请参考:
VS2010 + Studio for WPF 2014V3