Primary WPF APIs:
CheckBox (IsThreeState, IsChecked)RadioButton groupingToggleButtonPrimary Avalonia APIs:
CheckBox (IsThreeState, IsChecked)RadioButton (GroupName)ToggleButton and ToggleSwitch| WPF | Avalonia |
|---|---|
| tri-state checkbox | same concept (IsThreeState, nullable IsChecked) |
| radio groups by container/name | explicit GroupName for predictable grouping |
| toggle semantics | ToggleButton/ToggleSwitch |
WPF XAML:
<StackPanel>
<CheckBox Content="Archive"
IsThreeState="True"
IsChecked="{Binding ArchiveState, Mode=TwoWay}" />
<StackPanel Orientation="Horizontal">
<RadioButton GroupName="Priority" Content="High" IsChecked="{Binding IsHigh}" />
<RadioButton GroupName="Priority" Content="Low" IsChecked="{Binding IsLow}" />
</StackPanel>
</StackPanel>
Avalonia XAML:
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MyApp.ViewModels"
x:DataType="vm:PreferencesViewModel">
<StackPanel Spacing="8">
<CheckBox Content="Archive"
IsThreeState="True"
IsChecked="{CompiledBinding ArchiveState, Mode=TwoWay}" />
<StackPanel Orientation="Horizontal" Spacing="8">
<RadioButton GroupName="Priority"
Content="High"
IsChecked="{CompiledBinding IsHigh, Mode=TwoWay}" />
<RadioButton GroupName="Priority"
Content="Low"
IsChecked="{CompiledBinding IsLow, Mode=TwoWay}" />
</StackPanel>
<ToggleSwitch Content="Enable sync"
IsChecked="{CompiledBinding SyncEnabled, Mode=TwoWay}" />
</StackPanel>
</UserControl>
using Avalonia.Controls;
var archive = new CheckBox
{
Content = "Archive",
IsThreeState = true,
IsChecked = null
};
var high = new RadioButton { GroupName = "Priority", Content = "High" };
var low = new RadioButton { GroupName = "Priority", Content = "Low" };
var sync = new ToggleSwitch { Content = "Enable sync", IsChecked = true };
bool? in the view model for indeterminate state.GroupName values and avoid accidental cross-grouping.ToggleSwitch for setting-like states and keep labels explicit.