When building the GUI of a desktop application that uses standard elements (such as standard windows, buttons, text boxes, without any custom styling applied), the addition of custom visual elements (separators, moderately special things like a ruler or some other graphical output, etc.) is sometimes required. It is my understanding that it is usually good practice not to nail down any concrete colors for those (as they might conflict with whichever colors are configured in either the system or the overall theme of the UI toolkit), but stick to placeholders representing certain semantics.
How do I do this in Avalonia?
I see various bits and pieces, but no conclusive documentation:
BaseColorPalette.xamldefines various theme-dependent colors, which looks about right. But they are not really "semantically" labeled, i.e. I cannot tell which ones are supposed to be foreground, background, or separator colors.- Brush Names is more like what I am looking for, but it is specific to some extra Material design rather than one of the built-in Avalonia themes.
ProgressBar.xamluses placeholders likeThemeForegroundBrushorThemeAccentBrush, but I cannot figure out where these are defined or documented.ColorPaletteResourceslooks like it may contain the color definitions, but again, their names (let alone the lacking documentation) are not really telling about which color should be used for what. What is more, the documentation here points out "This class can only be used in Palettes." for some reason.- How to use theme variants appears to be spot-on, but the code sample then declares a custom
BackgroundBrushandForegroundBrushresource rather than showing how to use the background and foreground colors/brushes fitting with the active theme. - Fluent Theme shows some examples of what the Fluent theme looks like. The explanation of how to use it is cut short after showcasing how to reference the relevant Nuget package; after that, the article jumps right into defining custom color palettes rather than how to use the pre-defined ones.
- How to use resources exclusively shows examples where custom resource keys are defined rather than showcasing anywhere how to use resources supplied e.g. by the active theme.
- How to get the accent color for the current theme? appears to be asking the same question I have. However, the discussion first gets sidetracked by explanations on how to load any resources at all programmatically, then there's some confusion about system-wide color settings vs. theme colors (where I think the latter are more relevant in a given Avalonia app, where other controls are already drawn based on a theme, but I think the explanation on how to access the theme colors/brushes is then somehow missing), and then the discussion somehow ends on a post that defines custom colors once again.
- How to use "standard" theme colors in my Avalonia custom control from two years ago is kind of what I am asking. Unfortunately, the answer just contains a vague hint to look at the sources of existing controls. The example listed,
TextControlSelectionHighlightColor, looks very promising, but it appears to be defined in a file from the Fluent theme calledFluentControlResources.xaml. In there, that resource is listed in a section specifically titled, which makes me doubt these resources are meant for general consumption (or even guaranteed to be stable across Avalonia releases).
To clarfy what I'm after: System.Drawing still had a SystemBrushes class, which made this very easy. For WPF, I could use SystemColors. But how to retrieve the right colors for certain uses that comply with the currently active theme in my Avalonia UI?