Primary WinForms APIs:
BackColor, ForeColor, Font)Primary Avalonia APIs:
Style selectors and classesControlThemeStaticResource, dynamic resource patterns):pointerover, :pressed, :focus)| WinForms | Avalonia |
|---|---|
| set color/font on each control | reusable styles and resource dictionaries |
| designer theme drift | centralized theme resources |
| owner-draw for simple states | pseudo-class selectors and templates |
WinForms C#:
saveButton.BackColor = Color.FromArgb(20, 120, 200);
saveButton.ForeColor = Color.White;
saveButton.FlatStyle = FlatStyle.Flat;
Avalonia XAML:
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Styles.Resources>
<Color x:Key="AccentColor">#1478C8</Color>
<SolidColorBrush x:Key="AccentBrush" Color="{StaticResource AccentColor}" />
</Styles.Resources>
<Style Selector="Button.accent">
<Setter Property="Background" Value="{StaticResource AccentBrush}" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Padding" Value="12,6" />
</Style>
<Style Selector="Button.accent:pointerover">
<Setter Property="Opacity" Value="0.9" />
</Style>
</Styles>
<Button Classes="accent" Content="Save" />
using Avalonia.Controls;
using Avalonia.Media;
var save = new Button
{
Content = "Save",
Background = new SolidColorBrush(Color.Parse("#1478C8")),
Foreground = Brushes.White,
Padding = new Avalonia.Thickness(12, 6)
};
save.Classes.Add("accent");