回复 4楼xinren063的帖子
需要自定义 CellFactory 来实现,详细请参考代码:
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- List<test> datas = new List<test>();
- for (int i = 0; i < 100; i++)
- {
- test t = new test();
- t.Name = "fdsfds";
- datas.Add(t);
- }
- this.c1flexgrid1.TopLeftCells[0, 0] = "test";
- CellStyle cs = new CellStyle();
- cs.Background = new SolidColorBrush(Colors.Red);
- cs.HorizontalAlignment = HorizontalAlignment.Right;
- this.c1flexgrid1.ItemsSource = datas;
- this.c1flexgrid1.CellFactory = new MyCellFactory();
- }
- }
- public class test
- {
- public string name;
- public string Name
- {
- get;
- set;
- }
- }
- public class MyCellFactory : CellFactory
- {
- public override void ApplyCellStyles(C1FlexGrid grid, CellType cellType, CellRange rng, Border bdr)
- {
- var columnindex = rng.Column;
- var rowindex = rng.Row;
- var _textblock = bdr.Child as TextBlock;
- if (cellType == CellType.TopLeft)
- {
- bdr.Background = new SolidColorBrush(Colors.Red);
- bdr.BorderBrush = Brushes.Blue;
- bdr.BorderThickness = new Thickness(1);
- _textblock.TextDecorations = TextDecorations.Underline;
- _textblock.FontWeight = FontWeights.Bold;
- _textblock.FontSize = 15;
- _textblock.FontStyle = FontStyles.Italic;
- _textblock.TextAlignment = TextAlignment.Center;
- }
- }
- }
复制代码 |