Studio for WPF: 旋转 C1FlexGrid 合并单元格文本

使用表格控件,经常会使用到旋转文字角度的功能。使用 C1FlexGrid 控件,实现文本旋转是十分容易的,本章将阐述合并单元格旋转文字的实现方法。<img alt="Rotate Text in MergedRange" src="http://our.componentone.com/wp-content/uploads/2014/05/TransformedText_InMergedRange1.png">

发布于 2014/05/22 00:00

ComponentOne Enterprise

使用表格控件,经常会使用到旋转文字角度的功能。使用 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,效果图如下:

Rotate Text in MergedRange

更详细设置请参考:

VS2010 + Studio for WPF 2014V3

 

ComponentOne Enterprise | 下载试用

ComponentOne 是一套专注于企业 .NET开发、支持 .NET Core 平台,并完美集成于 Visual Studio 的第三方控件集,包含 300 多种 .NET开发控件,提供表格数据管理、数据可视化、报表和文档、日程安排、输入和编辑、导航和布局、系统提升工具等七大功能,被誉为“.NET开发的‘瑞士军刀’”。

ComponentOne 为您提供专业的产品咨询服务,并由技术支持工程师为您1对1解答。>> 发帖提问

相关产品
推荐相关案例
关注微信
葡萄城社区二维码

关注“葡萄城社区”

加微信获取技术资讯

加微信获取技术资讯

想了解更多信息,请联系我们, 随时掌握技术资源和产品动态