Styling Using ActiveStyles
Introduction
Gum can be restyled using an ActiveStyle object. Changes to ActiveStyle result in style changes for all controls created after the change is made. ActiveStyle can make it easy to restyle all controls without needing to make changes to each individual control.
Styling.ActiveStyle.Colors
Gum includes a Styling object which contains multiple color values for default styling. For example the Primary color can be changed using the following code:
Styling.ActiveStyle.Colors.Primary = Color.DarkGreen;The following properties exist on Colors:
Primary
Button Background
CheckBox Background
ComboBox DropdownIndicator
ListBoxItem Background (Selected)
MenuItem Background (Selected)
RadioButton Background
Slider Thumb Background
TextBox Caret
Window Background (Default only border)
Warning
FocusIndicators on all controls
Accent
ListBoxItem Background (Highlight)
MenuItem Background (Highlight)
InputBackground
ComboBox Background
ListBox Background
Menu Background
PasswordBox Background
ScrollViewer Background
Slider Track Background
Splitter Background
TextBox Background
SurfaceVariant
ScrollBar Track Background
IconDefault
CheckBox Check
RadioButton Radio
ScrollBar UpButton/DownButton Icon
TextPrimary
Button Text
CheckBox Text
ComboBox Text
Label
ListBoxItem Text
MenuItem Text
MenuItem SubmenuIndicator
PasswordBox Text
RadioButton Text
TextBox Text
TextMuted
PasswordBox PlaceholderTextInstance
TextBox PlaceholderTextInstance
Code Example: Applying Styles Before Creating Controls
The Styling.ActiveStyle.Color property includes styles that are used by controls when they are created. We can see how these affect controls by creating a sample project:
This code produces a set of controls which can be used to check how styling is applied.


We can prefix the following code before creating all of our controls:
By changing these colors, controls are created using the new colors:


Styling and Creation Order
Styling only applies after it has been set. Controls which are created before styling is set do not automatically update to the new style. The following code shows how order can impact how styling is assigned:

Last updated
Was this helpful?

