ColorPicker and ColorViewPrimary APIs:
ColorPicker (Color, ColorChanged, content alignment/template support)ColorView (Color, ColorChanged, IsAlphaEnabled, IsColorSpectrumVisible, IsColorPaletteVisible)ColorView advanced display options:
ColorModel, ColorSpectrumComponents, ColorSpectrumShapeIsColorPreviewVisible, IsColorComponentsVisible, IsColorModelVisibleReference docs:
02-html-css-selectors-cascade-variables-and-theming.md07-html-css-design-system-utilities-and-component-variants.mdcontrols/color-picker.mdcontrols/color-view.md| HTML/CSS idiom | Avalonia mapping |
|---|---|
<input type="color"> |
ColorPicker |
| custom hue/saturation/alpha panel | ColorView |
CSS custom property --accent |
bind Avalonia resource/VM color property |
preview swatch <div style="background: var(--accent)"> |
Border Background="{Binding AccentBrush}" |
HTML/CSS:
<label for="accent">Accent</label>
<input id="accent" type="color" value="#2f6fed" />
.preview {
inline-size: 40px;
block-size: 40px;
border-radius: 8px;
background: var(--accent);
}
Avalonia:
<StackPanel Spacing="8">
<ColorPicker Color="{CompiledBinding AccentColor, Mode=TwoWay}" />
<Border Width="40"
Height="40"
CornerRadius="8"
Background="{CompiledBinding AccentBrush}" />
</StackPanel>
For web UIs that include HSVA panels and alpha controls, ColorView gives the equivalent out of the box.
<ColorView Color="{CompiledBinding AccentColor, Mode=TwoWay}"
IsAlphaEnabled="True"
IsColorSpectrumVisible="True"
IsColorPaletteVisible="True"
IsColorPreviewVisible="True"
IsColorComponentsVisible="True"
IsColorModelVisible="True"
IsColorSpectrumSliderVisible="True" />
<section class="theme-editor">
<h3>Theme Accent</h3>
<input type="color" value="#ff6a00" />
<div class="swatch"></div>
</section>
.theme-editor {
display: grid;
gap: 8px;
max-inline-size: 360px;
}
.swatch {
inline-size: 100%;
block-size: 28px;
border-radius: 8px;
background: linear-gradient(90deg, var(--accent), #ffffff);
}
<StackPanel Spacing="8" MaxWidth="360">
<TextBlock Text="Theme Accent" />
<ColorPicker Color="{CompiledBinding AccentColor, Mode=TwoWay}" />
<ColorView Color="{CompiledBinding AccentColor, Mode=TwoWay}"
IsAlphaEnabled="True"
IsColorSpectrumVisible="True"
IsColorPaletteVisible="True" />
<Border Height="28"
CornerRadius="8"
Background="{CompiledBinding AccentBrush}" />
</StackPanel>
using Avalonia.Controls;
using Avalonia.Media;
var accentPicker = new ColorPicker
{
Color = Color.Parse("#FF6A00")
};
var accentView = new ColorView
{
Color = accentPicker.Color,
IsAlphaEnabled = true,
IsColorSpectrumVisible = true,
IsColorPaletteVisible = true
};
var swatch = new Border
{
Height = 28,
CornerRadius = new CornerRadius(8),
Background = new SolidColorBrush(accentPicker.Color)
};
accentPicker.ColorChanged += (_, e) =>
{
accentView.Color = e.NewColor;
swatch.Background = new SolidColorBrush(e.NewColor);
};
accentView.ColorChanged += (_, e) =>
{
accentPicker.Color = e.NewColor;
swatch.Background = new SolidColorBrush(e.NewColor);
};
var panel = new StackPanel { Spacing = 8, MaxWidth = 360 };
panel.Children.Add(new TextBlock { Text = "Theme Accent" });
panel.Children.Add(accentPicker);
panel.Children.Add(accentView);
panel.Children.Add(swatch);
Color (plus derived brushes) in the VM; avoid string parsing in hot paths.Dispatcher.UIThread.ColorView when you need spectrum/palette/model UI beyond basic pickers.