Skip to main content

Buttons and badges

HammerUI styles Avalonia's Button, ToggleButton and RepeatButton and gives them classes for their role, so a toolbar, a dialog footer and a tool rail each use the same buttons with a different class. It adds three small controls that sit next to buttons: Badge, ShortcutBadge and SegmentedControl.

Buttons​

<StackPanel Orientation="Horizontal" Spacing="8">
<Button Classes="accent" Content="Save" />
<Button Content="Cancel" />
<Button Classes="subtle" Content="Reset" />
<Button Classes="danger" Content="Delete" />
<Button Classes="icon" ToolTip.Tip="Undo">
<ui:SymbolIcon Data="{x:Static ui:Icons.Undo}" />
</Button>
</StackPanel>
ClassUse it for
noneOrdinary actions.
accentThe main action of a dialog or panel. Use one per area.
subtleQuiet actions that should not draw the eye, such as Reset.
dangerDestructive actions, such as Delete.
iconA square, borderless button holding a SymbolIcon. Give it a tooltip.
smallA shorter button; icon small is a small icon button, as in panel headers.

The classes apply to Button, RepeatButton and ToggleButton. A checked ToggleButton takes the subtle accent color.

Tool toggles​

ToggleButton.tool is a 36 × 36 tool button for a tool rail, with an accent indicator while checked. Put the tools of one rail in a Border.floating or a toolbar and keep one checked:

<Border Classes="floating">
<StackPanel Spacing="2">
<ToggleButton Classes="tool" IsChecked="True" ToolTip.Tip="Select">
<ui:SymbolIcon Data="{x:Static ui:Icons.MousePointer}" Size="18" />
</ToggleButton>
<ToggleButton Classes="tool" ToolTip.Tip="Move">
<ui:SymbolIcon Data="{x:Static ui:Icons.Move}" Size="18" />
</ToggleButton>
</StackPanel>
</Border>

ToggleButton.chip is a filter chip, such as the severities of a log: checked chips are raised, unchecked chips fade.

Badge​

A small pill label for counts and states. Its content is usually text.

<ui:Badge Content="Default" />
<ui:Badge Classes="accent" Content="New" />
<ui:Badge Classes="success" Content="Saved" />
<ui:Badge Classes="warning" Content="3 warnings" />
<ui:Badge Classes="danger" Content="Error" />
ClassTone
noneNeutral.
accent, success, warning, dangerThe matching palette color.

ShortcutBadge​

Shows a keyboard shortcut as a row of key caps, for menus, tooltips and command lists.

<ui:ShortcutBadge Text="Ctrl+Shift+P" />
PropertyWhat it does
TextThe shortcut, with keys separated by +. Ctrl++ shows the plus key.
KeysThe keys parsed from Text, read-only.

SegmentedControl​

A single choice from a few options, shown as a row of joined segments. It is a ListBox, so bind ItemsSource and SelectedItem or SelectedIndex as you would for a list.

<ui:SegmentedControl SelectedIndex="1">
<ui:SegmentedControlItem Content="Day" />
<ui:SegmentedControlItem Content="Week" />
<ui:SegmentedControlItem Content="Month" />
</ui:SegmentedControl>

Segments share the width equally. When the control is too narrow for its segments, they continue on another row rather than cutting off their content.

  • Shell styles for buttons in the app bar, tool strip and status bar.
  • Icons for the icons inside icon buttons.