Troubleshooting
Avalonia styling system is a mix of XAML and CSS styling approaches, so developers with knowledge of only one of these technologies can be confused by details of another one.
Let's imagine a problem when one or all style setters are not applied to the control. Below we will list common possible reasons and solutions.
Selector targets a control that doesn't exist
Avalonia selectors, like CSS selectors, do not raise any errors or warnings, when there are no controls which can be matched by the selector. This includes using a name or class that doesn't exist or a child selector when there are no children to match the inner selector. The reason is simple, one style can target many controls, that can be created or removed at runtime, so there is no possible way to validate the selector.
Target property is overridden by another style
Styles are applied in order of declaration. If there are multiple style files that target the same control property, one style can override the other:
<Style Selector="TextBlock.header">
<Style Property="Foreground" Value="Blue" />
<Style Property="FontSize" Value="16" />
</Style>
<Style Selector="TextBlock.header">
<Style Property="Foreground" Value="Green" />
</Style>
<StyleInclude Source="Style1.axaml" />
<StyleInclude Source="Style2.axaml" />
Here styles from file Styles1.axaml were applied first, so setters in styles of file Styles2.axaml take priority. The resulting TextBlock will have FontSize="16" and Foreground="Green". The same order prioritization happens within style files also.
Locally set Properties override Styles
Similarly, to WPF, Avalonia properties can have multiple values, often of different priorities.
In this example you can see that local value (defined directly on the control) has higher priority than style value, so text block will have red foreground:
<TextBlock Classes="header" Foreground="Red" />
...
<Style Selector="TextBlock.header">
<Setter Property="Foreground" Value="Green" />
</Style>