avalonia-controls-input
Use when working with Avalonia input controls: Button, ToggleButton, RadioButton, CheckBox, TextBox, ComboBox, Slider, Calendar, DatePicker, TimePicker, NumericUpDown, or VirtualKeyboard. Covers key properties, events, binding patterns, placeholder text (PlaceholderText in 12, Watermark in 11.x), ToggleButton IsCheckedChanged, touch/pen selection, and common pitfalls for Avalonia 11.3, 12.0 and 12.1.
linuxdevel · 已有静态检查记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add linuxdevel/Avalonia-skills --skill avalonia-controls-input技能说明
name: avalonia-controls-input description: Use when working with Avalonia input controls: Button, ToggleButton, RadioButton, CheckBox, TextBox, ComboBox, Slider, Calendar, DatePicker, TimePicker, NumericUpDown, or VirtualKeyboard. Covers key properties, events, binding patterns, placeholder text (PlaceholderText in 12, Watermark in 11.x), ToggleButton IsCheckedChanged, touch/pen selection, and common pitfalls for Avalonia 11.3, 12.0 and 12.1.
Avalonia Input Controls
Overview
Input controls capture user data or trigger actions. All support IsEnabled, IsVisible, and standard styling.
Button
| Property | Type | Notes |
|---|---|---|
Content | object | Any content, including XAML subtrees |
Command | ICommand | Bound command; auto-manages IsEnabled |
CommandParameter | object | Passed to command |
IsDefault | bool | Triggers on Enter |
IsCancel | bool | Triggers on Escape |
ClickMode | ClickMode | Release (default), Press, Hover |
Events: Click
Variants: RepeatButton (fires Click repeatedly while held), ToggleButton (stateful press)
ToggleButton / CheckBox / RadioButton state events: use IsCheckedChanged (works in all versions). The Checked / Unchecked / Indeterminate events were removed in 12.0 — they only exist in 11.x (obsolete there). Or just bind IsChecked.
<!-- Simple command button -->
<Button Content="Save" Command="{Binding SaveCommand}" IsDefault="True"/>
<!-- Button with icon + text -->
<Button Click="OnClick">
<StackPanel Orientation="Horizontal" Spacing="8">
<PathIcon Data="M17 3H5c-1.1 0-2 .9-2 2v14l7-3 7 3V5c0-1.1-.9-2-2-2z" Width="16" Height="16"/>
<TextBlock Text="Save" VerticalAlignment="Center"/>
</StackPanel>
</Button>
<!-- RepeatButton -->
<RepeatButton Content="+" Command="{Binding IncrementCommand}" Delay="400" Interval="100"/>
<!-- ToggleButton -->
<ToggleButton Content="Bold" IsChecked="{Binding IsBold}"/>
<!-- React to state change (all versions). Checked/Unchecked events: (11.x) only -->
<ToggleButton Content="Bold" IsCheckedChanged="OnBoldChanged"/>
private void OnBoldChanged(object? sender, RoutedEventArgs e)
{
var isOn = ((ToggleButton)sender!).IsChecked == true;
}
CheckBox
| Property | Type | Notes |
|---|---|---|
IsChecked | bool? | null = indeterminate |
IsThreeState | bool | Enables null/indeterminate state |
Content | object | Label displayed next to box |
<!-- Basic binding -->
<CheckBox Content="Enable notifications" IsChecked="{Binding IsNotificationsEnabled}"/>
<!-- Three-state -->
<CheckBox Content="Select all" IsThreeState="True" IsChecked="{Binding AllSelected}"/>
// Handle indeterminate in ViewModel
private bool? _allSelected;
public bool? AllSelected
{
get => _allSelected;
set => SetProperty(ref _allSelected, value);
}
RadioButton
| Property | Type | Notes |
|---|---|---|
IsChecked | bool | TwoWay by default |
GroupName | string | Groups buttons across panels |
Content | object | Label |
<!-- Grouped by GroupName -->
<StackPanel>
<RadioButton Content="Small" GroupName="Size" IsChecked="{Binding IsSmall}"/>
<RadioButton Content="Medium" GroupName="Size" IsChecked="{Binding IsMedium}"/>
<RadioButton Content="Large" GroupName="Size" IsChecked="{Binding IsLarge}"/>
</StackPanel>
<!-- Grouped by parent panel (no GroupName needed) -->
<StackPanel>
<RadioButton Content="Option A"/>
<RadioButton Content="Option B"/>
</StackPanel>
Touch/pen (12.0+): selection in
ComboBox,ListBox,TabControl,TreeViewhappens on pointer release, not press.ListBoxItem/TreeViewItemhandle selection themselves — don't intercept selection at theItemsControllevel (overrideShouldTriggerSelection/UpdateSelectionFromEventinstead).
Tip: For enum-based selection, bind each
IsCheckedto a converter comparing the enum value, or useItemsControlwithRadioButtonitems.
TextBox
| Property | Type | Notes |
|---|---|---|
Text | string | TwoWay by default — do not add Mode=TwoWay |
PlaceholderText | string | Placeholder text (12.0+). Watermark is the (11.x) name — obsolete in 12 (warns) |
PlaceholderForeground | IBrush | Placeholder color (12.0+) (WatermarkForeground in 11.x) |
UseFloatingPlaceholder | bool | Placeholder floats above text when focused (12.0+) (UseFloatingWatermark in 11.x) |
MaxLength | int | 0 = unlimited |
AcceptsReturn | bool | Multiline input |
TextWrapping | TextWrapping | NoWrap, Wrap, WrapWithOverflow |
IsReadOnly | bool | Prevents editing |
PasswordChar | char | Masks input (e.g. •) |
SelectionStart | int | Caret/selection start |
SelectionLength | int | Selection length |
InnerLeftContent | object | Icon inside left edge |
InnerRightContent | object | Icon inside right edge |
Events: TextChanged, TextChanging, LostFocus, KeyDown
<!-- Basic (12.0+). In 11.x use Watermark="Enter name..." -->
<TextBox PlaceholderText="Enter name..." Text="{Binding Name}" MaxLength="100"/>
<!-- Multiline -->
<TextBox AcceptsReturn="True" TextWrapping="Wrap" Height="120" Text="{Binding Notes}"/>
<!-- Password -->
<TextBox PasswordChar="•" PlaceholderText="Password" Text="{Binding Password}"/>
<!-- With inner icon -->
<TextBox PlaceholderText="Search..." PlaceholderForeground="Gray" UseFloatingPlaceholder="False">
<TextBox.InnerLeftContent>
<PathIcon Data="M15.5 14h-.79l-.28-.27A6.471..." Width="16" Height="16" Margin="4,0"/>
</TextBox.InnerLeftContent>
</TextBox>
阅读完整来源 ↗The same
PlaceholderText/PlaceholderForegroundpair (12.0+) also exists onAutoCompleteBox,CalendarDatePickerandNumericUpDown(each keeps obsoleteWatermark/WatermarkForegroundfor 11.x compatibility