跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
效率与协作

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

PropertyTypeNotes
ContentobjectAny content, including XAML subtrees
CommandICommandBound command; auto-manages IsEnabled
CommandParameterobjectPassed to command
IsDefaultboolTriggers on Enter
IsCancelboolTriggers on Escape
ClickModeClickModeRelease (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

PropertyTypeNotes
IsCheckedbool?null = indeterminate
IsThreeStateboolEnables null/indeterminate state
ContentobjectLabel 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

PropertyTypeNotes
IsCheckedboolTwoWay by default
GroupNamestringGroups buttons across panels
ContentobjectLabel
<!-- 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, TreeView happens on pointer release, not press. ListBoxItem/TreeViewItem handle selection themselves — don't intercept selection at the ItemsControl level (override ShouldTriggerSelection / UpdateSelectionFromEvent instead).

Tip: For enum-based selection, bind each IsChecked to a converter comparing the enum value, or use ItemsControl with RadioButton items.


TextBox

PropertyTypeNotes
TextstringTwoWay by default — do not add Mode=TwoWay
PlaceholderTextstringPlaceholder text (12.0+). Watermark is the (11.x) name — obsolete in 12 (warns)
PlaceholderForegroundIBrushPlaceholder color (12.0+) (WatermarkForeground in 11.x)
UseFloatingPlaceholderboolPlaceholder floats above text when focused (12.0+) (UseFloatingWatermark in 11.x)
MaxLengthint0 = unlimited
AcceptsReturnboolMultiline input
TextWrappingTextWrappingNoWrap, Wrap, WrapWithOverflow
IsReadOnlyboolPrevents editing
PasswordCharcharMasks input (e.g. •)
SelectionStartintCaret/selection start
SelectionLengthintSelection length
InnerLeftContentobjectIcon inside left edge
InnerRightContentobjectIcon 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 / PlaceholderForeground pair (12.0+) also exists on AutoCompleteBox, CalendarDatePicker and NumericUpDown (each keeps obsolete Watermark / WatermarkForeground for 11.x compatibility

阅读完整来源 ↗