找回密码
 立即注册

QQ登录

只需一步,快速开始

xinren063

高级会员

46

主题

209

帖子

1378

积分

高级会员

积分
1378

活字格认证

xinren063
高级会员   /  发表于:2013-8-14 17:51  /   查看:6843  /  回复:3
请教如何操作

3 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2013-8-14 19:24:00
沙发
回复 1楼xinren063的帖子

xinren063 你好,

关于 FlexGrid 问题,请到 ComponentOne 专区发帖。我会把帖子移动到相应版块。

在字体上添加横线方法如下:


  1. public class MyCellFactory : C1.WPF.FlexGrid.CellFactory
  2.     {
  3.         public override void CreateCellContent(C1.WPF.FlexGrid.C1FlexGrid grid, System.Windows.Controls.Border bdr, C1.WPF.FlexGrid.CellRange rng)
  4.         {
  5.             base.CreateCellContent(grid, bdr, rng);

  6.             if (rng.Column == 0)
  7.             {
  8.                 var obj = bdr.Child;
  9.                 if (obj.GetType().Equals(typeof(TextBlock)))
  10.                 {
  11.                     if (!(((TextBlock)obj).Text == string.Empty))
  12.                     {
  13.                         bdr.Child = null;
  14.                         double width = 0;
  15.                         double height = 0;
  16.                         if ((TextBlock)obj != null)
  17.                         {
  18.                             width = ((TextBlock)obj).ActualWidth;
  19.                             height = ((TextBlock)obj).ActualHeight;
  20.                         }
  21.                         Line ln = new Line();
  22.                         ln.Stroke = new SolidColorBrush(Colors.Red);
  23.                         ln.StrokeThickness = 1;
  24.                         ln.X1 = 0;
  25.                         ln.Y1 = (height / 2) + 3;
  26.                         ln.X2 = width + 1;
  27.                         ln.Y2 = (height / 2) + 3;
  28.                         Grid grd = new Grid();
  29.                         grd.Children.Add(ln);
  30.                         grd.Children.Add(obj);
  31.                         ((TextBlock)obj).Foreground = new SolidColorBrush(Colors.Green);
  32.                         bdr.Child = grd;
  33.                     }
  34.                 }
  35.             }

  36.         }
  37.     }
复制代码
回复 使用道具 举报
xinren063
高级会员   /  发表于:2013-8-16 08:42:00
板凳
回复 2楼iceman的帖子

如何使得wpf的c1FlexGrid的一行上所有字体变斜呢?
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-8-16 12:13:00
地板
回复 3楼xinren063的帖子

可以通过以下代码测试,包含了斜体、贯穿线、粗体:

  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.     }
复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部