找回密码
 立即注册

QQ登录

只需一步,快速开始

jxlxl

论坛元老

6

主题

16

帖子

1万

积分

论坛元老

积分
12112

活字格认证

jxlxl
论坛元老   /  发表于:2015-2-11 08:37  /   查看:4254  /  回复:1
Hi C1朋友,
       我现有个需求是将C1FlexGrid第一行的字体加粗。我的做法是加了LoadedRows事件,
if (AnalysisFlexgridDataGrid != null && AnalysisFlexgridDataGrid.Rows != null && AnalysisFlexgridDataGrid.Rows.Count > 0)
                {
                       AnalysisFlexgridDataGrid.Rows[0].FontWeight = FontWeights.Bold;
                }
第一次Loaded完FlexGrid第一行的字体有改变, 如果FlexGrid的itemSource改变,C1FlexGrid能正确显示改变后的Source。 但是它的Rows.Count == 0. 就无法改变第一行的字体。

请问有什么其他办法?

多谢多谢!

1 个回复

倒序浏览
Alice
社区贡献组   /  发表于:2015-2-11 15:12:00
沙发
回复 1楼jxlxl的帖子

可以使用CellFactory来实现。
包含斜体、贯穿线和粗体,代码参考:
  1. public class MyCellFactory : C1.WPF.FlexGrid.CellFactory
  2.     {
  3.         public override void ApplyCellStyles(C1.WPF.FlexGrid.C1FlexGrid grid, C1.WPF.FlexGrid.CellType cellType, C1.WPF.FlexGrid.CellRange rng, Border bdr)
  4.         {
  5.             base.ApplyCellStyles(grid, cellType, rng, bdr);

  6.             if (cellType == C1.WPF.FlexGrid.CellType.Cell)
  7.             {
  8.                 var row = grid.Rows[rng.Row].Index;
  9.                 var _textblock = bdr.Child as TextBlock;

  10.                 if (row % 2 == 0)
  11.                 {
  12.                     //underline text
  13.                     _textblock.FontWeight = FontWeights.Bold;
  14.                     _textblock.FontStyle = FontStyles.Italic;
  15.                     _textblock.TextDecorations = TextDecorations.Strikethrough;
  16.                 }
  17.                 else
  18.                 {
  19.                     //Strikeout text
  20.                     bdr.Child = null;
  21.                     double width = 0;
  22.                     double height = 0;
  23.                     if (_textblock != null)
  24.                     {
  25.                         width = _textblock.ActualWidth;
  26.                         height = _textblock.ActualHeight;
  27.                     }

  28.                     Line _line = new Line();
  29.                     _line.Stroke = new SolidColorBrush(Colors.Black);
  30.                     _line.StrokeThickness = 1;
  31.                     _line.X1 = 0;
  32.                     _line.Y1 = (height / 2) + 3;
  33.                     _line.X2 = width + 1;
  34.                     _line.Y2 = (height / 2) + 3;

  35.                     Grid grd = new Grid();
  36.                     grd.Children.Add(_line);

  37.                     _textblock.FontWeight = FontWeights.Thin;
  38.                     _textblock.FontStyle = FontStyles.Italic;
  39.                     grd.Children.Add(_textblock);

  40.                     bdr.Child = grd;
  41.                 }
  42.             }
  43.         }
  44.     }

  45.     public class TestData
  46.     {
  47.         public string Name { get; set; }
  48.         public string Title { get; set; }
  49.     }
复制代码


安装产品后,也可以在如下路径找到CellFactory示例演示:
\Documents\ComponentOne Samples\Studio for WPF\C1.WPF.FlexGrid\CS\UnboundCellFactory
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部