/// <summary>
        /// Applies custom styles to the outline row.
        /// </summary>
        public override void ApplyCellStyles(C1FlexGrid grid, CellType cellType, CellRange range, Border bdr)
        {
            if (cellType == CellType.Cell)
            {
                bool hasAlignment = false;

                // get selection state for the range
                var selState = grid.GetSelectedState(range);

                // apply row style
                var row = grid.Rows[range.Row];
                if (row.CellStyle != null)
                {
                    row.CellStyle.Apply(bdr, selState);
                    hasAlignment |= row.CellStyle.HorizontalAlignment.HasValue;
                }

                // apply column style
                var col = grid.Columns[range.Column];
                if (col.CellStyle != null)
                {
                    col.CellStyle.Apply(bdr, selState);
                    hasAlignment |= col.CellStyle.HorizontalAlignment.HasValue;
                }

                // apply cell style
                var xlr = row as ExcelRow;
                if (xlr != null)
                {
                    var s = xlr.GetCellStyle(col);
                    if (s != null)
                    {
                        // leave hyperlink foreground alone...
                        if (bdr.Child is HyperlinkButton)
                        {
                            s.Foreground = null;
                        }

                        // apply standard CellStyle stuff
                        s.Apply(bdr, selState);
                        hasAlignment |= s.HorizontalAlignment.HasValue;

                        // apply general alignment
                        if (!hasAlignment)
                        {
                            var content = grid[range.Row, range.Column];
                            if (IsNumeric(content))
                            {
                                _styleRight.Apply(bdr, selState);
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        public override FrameworkElement CreateCell(C1FlexGrid grid, CellType cellType, CellRange range)
        {
            // let base class to most of the work
            var cell = base.CreateCell(grid, cellType, range);

            // keep the selectionbackground
            if (grid.GetSelectedState(range) != SelectedState.None)
                return cell;

            // apply green background if necessary
            if (cellType == CellType.Cell)
            {
                var cellValue = grid[range.Row, range.Column];
                if (cellValue is double && (double)cellValue > 500)
                {
                    var border = cell as Border;
                    border.Background = _greenBrush;
                }
            }

            // done
            return cell;
        }
示例#3
0
 /// <summary>
 ///     Creates a <see cref="T:System.Windows.Controls.Border" /> element that represents the background and
 ///     border of a grid cell and contains the cell data.
 /// </summary>
 /// <param name="grid">
 ///     <see cref="T:C1.WPF.FlexGrid.C1FlexGrid" /> that owns the cell.
 /// </param>
 /// <param name="cellType">
 ///     <see cref="T:C1.WPF.FlexGrid.CellType" /> that specifies the type of cell to be created.
 /// </param>
 /// <param name="rng">
 ///     <see cref="T:C1.WPF.FlexGrid.CellRange" /> that specifies the row and column represented by the cell.
 /// </param>
 /// <returns>
 ///     A <see cref="T:System.Windows.Controls.Border" /> element that represents the background and
 ///     border of a grid cell.
 /// </returns>
 public virtual Border CreateCellBorder(C1FlexGrid grid, CellType cellType, CellRange rng)
 {
     Border bdr = new Border();
     switch (cellType)
     {
         case CellType.Cell:
         {
             Row row = grid.Rows[rng.Row];
             bdr.DataContext = row.DataItem;
             if (grid.AlternatingRowBackground == null || (grid.Rows[rng.Row].VisibleIndex & 1) == 0 || rng.RowSpan > 1)
             {
                 bdr.Background = grid.RowBackground;
             }
             else
             {
                 bdr.Background = grid.AlternatingRowBackground;
             }
             if (row is GroupRow && grid.GroupRowBackground != null)
             {
                 bdr.Background = grid.GroupRowBackground;
             }
             if (row is NewRowTemplate && grid.NewRowBackground != null)
             {
                 bdr.Background = grid.NewRowBackground;
             }
             bdr.BorderThickness = GetBorderThickness(grid, rng);
             bdr.BorderBrush = grid.GridLinesBrush;
             bdr.Padding = GetCellPadding(grid, grid.Cells, rng);
             break;
         }
         case CellType.ColumnHeader:
         case CellType.ColumnFooter:
             bdr.BorderThickness = _bdrFixed;
             bdr.BorderBrush = grid.HeaderGridLinesBrush;
             bdr.Padding = ((cellType == CellType.ColumnHeader) ? GetCellPadding(grid, grid.ColumnHeaders, rng) : GetCellPadding(grid, grid.ColumnFooters, rng));
             if (cellType == CellType.ColumnFooter || grid.ColumnHeaderSelectedBackground == null ||
                 grid.GetSelectedState(new CellRange(-1, rng.Column)) == SelectedState.None)
             {
                 bdr.Background = grid.ColumnHeaderBackground;
             }
             else
             {
                 bdr.Background = grid.ColumnHeaderSelectedBackground;
             }
             break;
         case CellType.RowHeader:
         case CellType.BottomLeft:
             bdr.BorderThickness = _bdrFixed;
             bdr.BorderBrush = grid.HeaderGridLinesBrush;
             bdr.Padding = _padding;
             if (cellType == CellType.BottomLeft || grid.RowHeaderSelectedBackground == null ||
                 grid.GetSelectedState(new CellRange(rng.Row, -1)) == SelectedState.None)
             {
                 bdr.Background = grid.RowHeaderBackground;
             }
             else
             {
                 bdr.Background = grid.RowHeaderSelectedBackground;
             }
             break;
         case CellType.TopLeft:
             bdr.Background = grid.TopLeftCellBackground;
             bdr.BorderThickness = _bdrFixed;
             bdr.BorderBrush = grid.HeaderGridLinesBrush;
             bdr.Padding = _padding;
             break;
         case CellType.BottomRight:
             bdr.Background = grid.BottomRightCellBackground;
             break;
     }
     if (bdr.Background == null)
     {
         bdr.Background = _brTransparent;
     }
     bdr.Language = grid.Language;
     return bdr;
 }
示例#4
0
 private void CustomizeCellStyle(C1FlexGrid grid, CellType cellType, CellRange rng, Border bdr, bool editor)
 {
     if (cellType == CellType.Cell)
     {
         switch (grid.GetSelectedState(rng))
         {
             case SelectedState.Selected:
                 _csSelected.Background = grid.SelectionBackground;
                 _csSelected.Foreground = grid.SelectionForeground;
                 _csSelected.Apply(bdr);
                 break;
             case SelectedState.Cursor:
                 if (editor && grid.EditorBackground != null)
                 {
                     _csSelected.Background = grid.EditorBackground;
                 }
                 else
                 {
                     _csSelected.Background = grid.CursorBackground;
                 }
                 if (editor && grid.EditorForeground != null)
                 {
                     _csSelected.Foreground = grid.EditorForeground;
                 }
                 else
                 {
                     _csSelected.Foreground = grid.CursorForeground ?? grid.SelectionForeground;
                 }
                 _csSelected.Apply(bdr);
                 break;
         }
         if (grid.Rows[rng.Row] is GroupRow && rng.Column == 0)
         {
             FrameworkElement frameworkElement = bdr.Child as FrameworkElement;
             if (frameworkElement != null)
             {
                 frameworkElement.HorizontalAlignment = HorizontalAlignment.Left;
             }
         }
     }
     ApplyCellStyles(grid, cellType, rng, bdr);
 }