The grid’s colors, and which elements it draws, can be changed at run time — to match your application’s theme, or to give a read-only view a quieter look.
Settings go on the control’s Viewport, followed by RefreshExternal() to repaint. The same
code works on WinForms, WPF and Avalonia.
Colors
using unvell.ReoGrid.Core.Rendering;
GridTheme theme = viewport.Theme;
theme.Background = 0xFFFFFFFF; // the sheet's ground color
theme.GridLine = 0xFFE0E0E0; // grid lines where there is no cell border
theme.HeaderBackground = 0xFFF3F3F3; // the row and column headers
theme.HeaderText = 0xFF333333;
theme.SelectionBorder = 0xFF12A4CB; // the selection frame
theme.SelectionFill = 0x2612A4CB; // the selection fill (the top 8 bits are the opacity)
Colors are uint ARGB (0xAARRGGBB). For something translucent, like SelectionFill,
the first two digits are the opacity.
What you can color
| Property | Applies to | Default |
|---|---|---|
Background | The sheet’s ground | 0xFFFFFFFF |
GridLine | Grid lines | 0xFFE0E0E0 |
HeaderBackground | Row and column header background | 0xFFF3F3F3 |
HeaderText | Header text | 0xFF333333 |
HeaderLine | Header separators | 0xFFCCCCCC |
HeaderSelectedBackground | The selected row/column header | 0xFFCDEBF4 |
FreezeLine | The line marking the freeze position | 0xFF808080 |
SelectionBorder | The selection frame and fill handle | 0xFF12A4CB |
SelectionFill | The selection’s fill | 0x2612A4CB |
OutlinePanelBackground | The outline panel background | 0xFFF3F3F3 |
OutlinePanelBorder | The outline panel border | 0xFFCCCCCC |
OutlineButtonBackground | [+] / [-] button background | 0xFFFFFFFF |
OutlineButtonBorder | [+] / [-] button border and connectors | 0xFF808080 |
OutlineButtonText | Level-number button text | 0xFF333333 |
Cell text and background colors are styles, not theme — see StyleRecord. The theme decides only the chrome around the sheet.
Going dark
// a dark palette. Replacing the whole GridTheme works too
viewport.Theme = new GridTheme
{
Background = 0xFF1E1E1E,
GridLine = 0xFF3A3A3A,
HeaderBackground = 0xFF2A2A2A,
HeaderText = 0xFFDDDDDD,
HeaderLine = 0xFF3A3A3A,
HeaderSelectedBackground = 0xFF15414C,
SelectionBorder = 0xFF12A4CB,
SelectionFill = 0x3312A4CB,
OutlinePanelBackground = 0xFF2A2A2A,
OutlinePanelBorder = 0xFF3A3A3A,
OutlineButtonBackground = 0xFF1E1E1E,
OutlineButtonBorder = 0xFF808080,
OutlineButtonText = 0xFFDDDDDD,
};
With a dark theme, you also have to change the cell text color. The theme only touches
chrome, so the default black text would be unreadable on a dark ground. Set the color in the
sheet’s default style (ws.RootStyle).
ws.RootStyle = ws.RootStyle with { Color = 0xFFDDDDDD };
Toggling elements
Grid lines, headers and the outline panel are control properties.
control.ShowGridLines = false; // grid lines
control.ShowHeaders = false; // row and column headers (A B C / 1 2 3)
control.ShowOutlines = false; // the outline (grouping) panel
ShowHeaders and ShowOutlines change the size of the scrollable area, so the scrollbars
adjust automatically.
To build something that does not read as a spreadsheet — a report preview, say — turning off both grid lines and headers gets you most of the way.
Finer-grained elements live on the Viewport itself.
viewport.RowHeaderWidth = 60; // row header width (logical pixels)
viewport.ColumnHeaderHeight = 24; // column header height
viewport.ShowSelection = false; // no selection frame (for a read-only view)
viewport.ShowFillHandle = false; // no auto-fill handle
viewport.ShowImages = false; // do not draw images
The row header defaults to 46 wide and the column header to 22 tall. On a sheet whose row numbers reach seven digits (a million rows), the defaults can look cramped.
Getting a change on screen
After touching the Viewport directly, ask for a repaint.
control.RefreshExternal();
Changes made through control properties (ShowGridLines and the rest) repaint themselves —
no call needed.
Effect on printing
Theme colors apply to the screen only. Printing and PDF export build their own viewport and therefore always use the default palette (white ground, grey grid lines). Printing with a dark theme applied will not produce a black page.
All that the print side toggles is whether grid lines and headers appear
(PrintSettings.ShowGridLines / ShowHeaders — see
Printing and Page Setup).