Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,50 +1,123 @@
---
description: "A button that's styled for use in a CommandBar."
---

# AppBarButton

We're still working on this, coming soon!

{/* {
"UniqueId": "AppBarButton",
"Title": "AppBarButton",
"Subtitle": "A button that's styled for use in a CommandBar.",
"ImagePath": "ms-appx:///Assets/ControlImages/AppBarButton.png",
"ImageIconPath": "ms-appx:///Assets/ControlIcons/AppBarButtonIcon.png",
"Description": "App bar buttons differ from standard buttons in several ways:\n- Their default appearance is a transparent background with a smaller size.\n- You use the Label and Icon properties to set the content instead of the Content property. The Content property is ignored.\n- The button's IsCompact property controls its size.",
"Content": "<p>You can open the app bar and toggle the IsCompact button to see how the app bar buttons on this page change.</p><p>Use the <b>Label</b> and <b>Icon</b> properties to define the content of the app bar buttons. Set the <b>Label</b> property to a string to specify the text label. The label is shown by default but is hidden when the button is in its compact state, so you also need to specify a meaningful icon. To do that, set the button's <b>Icon</b> property to an element derived from the <b>IconElement</b> class. Four kinds of icon elements are provided:</p><p><b>FontIcon</b> - The icon is based on a glyph from the specified font family.</p><p><b>BitmapIcon</b> - The icon is based on a bitmap image file with the specified Uri.</p><p><b>PathIcon</b> - The icon is based on Path data.</p><p><b>SymbolIcon</b> - The icon is based on a predefined list of glyphs from the Segoe UI Symbol font.</p><p>Look at the <i>AppBarButtonPage.xaml</i> file in Visual Studio to see the full code for this page.</p>",
"IsNew": false,
"IsUpdated": false,
"Docs": [
{
"Title": "AppBarButton - API",
"Uri": "https://docs.microsoft.com/windows/winui/api/microsoft.ui.xaml.controls.appbarbutton"
},
{
"Title": "SymbolIcon - API",
"Uri": "https://docs.microsoft.com/windows/winui/api/microsoft.ui.xaml.controls.symbolicon"
},
{
"Title": "FontIcon - API",
"Uri": "https://docs.microsoft.com/windows/winui/api/microsoft.ui.xaml.controls.fonticon"
},
{
"Title": "BitmapIcon - API",
"Uri": "https://docs.microsoft.com/windows/winui/api/microsoft.ui.xaml.controls.bitmapicon"
},
{
"Title": "PathIcon - API",
"Uri": "https://docs.microsoft.com/windows/winui/api/microsoft.ui.xaml.controls.pathicon"
},
{
"Title": "Guidelines",
"Uri": "https://docs.microsoft.com/windows/apps/design/controls/command-bar"
}
],
"RelatedControls": [
"AppBarToggleButton",
"AppBarSeparator",
"CommandBar"
]
}, */}
---
description: "A button that's styled for use in a CommandBar."
---

# AppBarButton

Use an AppBarButton for commands hosted in a [CommandBar](./command-bar), a [CommandBarFlyout](./command-bar-flyout), or anywhere else you want a button that follows the same icon-and-label styling. AppBarButton differs from a plain `Button` in a few ways:

- Its default appearance is a transparent background at a smaller size than a standard button.

- You set its content through the **Label** and **Icon** properties instead of `Content`.

- Its **IsCompact** property controls whether the label is shown at all, or the button shrinks down to just its icon.

- **Class**: [iNKORE.UI.WPF.Modern.Controls](..)[.AppBarButton](.)

- **Inheritance**: [Object](https://learn.microsoft.com/en-us/dotnet/api/system.object) → (...) → [ButtonBase](https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.primitives.buttonbase) → [Button](https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.button) → [AppBarButton](.)

## Examples

### A basic AppBarButton with an icon

Set **Label** to the button's text, and **Icon** to any `IconElement`, most commonly a **FontIcon**:

```xml
<ui:AppBarButton
Click="AppBarButton_Click"
Label="Home">
<ui:AppBarButton.Icon>
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Home}" />
</ui:AppBarButton.Icon>
</ui:AppBarButton>
```

**Icon** also accepts a **PathIcon** (or any other `IconElement`) if a font glyph doesn't cover what you need:

```xml
<ui:AppBarButton Label="Custom">
<ui:AppBarButton.Icon>
<ui:PathIcon Data="F1 M 20,20L 24,10L 24,24L 5,24" />
</ui:AppBarButton.Icon>
</ui:AppBarButton>
```

### Binding a command

AppBarButton works with the same `Command`/`CommandParameter`/`CommandBindings` you'd use on any `Button`:

```xml
<ui:AppBarButton
Command="Save"
Label="Save">
<ui:AppBarButton.CommandBindings>
<CommandBinding Command="Save" CanExecute="Save_CanExecute" />
</ui:AppBarButton.CommandBindings>
<ui:AppBarButton.Icon>
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Save}" />
</ui:AppBarButton.Icon>
</ui:AppBarButton>
```

### Attaching a flyout

Set **Flyout** to show a [MenuFlyout](./menu-flyout) (or any `FlyoutBase`) when the button is clicked, instead of raising `Click`:

```xml
<ui:AppBarButton Label="Sort">
<ui:AppBarButton.Icon>
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Sort}" />
</ui:AppBarButton.Icon>
<ui:AppBarButton.Flyout>
<ui:MenuFlyout>
<MenuItem Header="By rating" Click="MenuFlyoutItem_Click" Tag="rating" />
<MenuItem Header="By match" Click="MenuFlyoutItem_Click" Tag="match" />
<MenuItem Header="By distance" Click="MenuFlyoutItem_Click" Tag="distance" />
</ui:MenuFlyout>
</ui:AppBarButton.Flyout>
</ui:AppBarButton>
```

## Remarks

### IsCompact and label position

**IsCompact** shrinks the button down so only the icon shows, which is what a [CommandBar](./command-bar) does automatically to primary commands when it runs out of horizontal room. **LabelPosition** lets an individual button opt out of the bar's **DefaultLabelPosition**, for example collapsing just one button's label while the rest keep theirs.

### Icon types

**Icon** accepts any `IconElement`. This library ports four of them from WinUI:

- **FontIcon** — a glyph from an icon font, most commonly `SegoeFluentIcons`.

- **PathIcon** — a vector icon described with `Path` mini-language geometry data.

- **BitmapIcon** / **ImageIcon** — an icon based on a bitmap image.

`SymbolIcon` also exists, ported from WinUI, but it's marked obsolete in favor of `FontIcon`.

### InputGestureText vs. keyboard accelerators

**InputGestureText** just displays a hint string (like "Ctrl+S") next to the button's label or in its overflow row, it does not by itself make that shortcut work. Wire up the actual shortcut the normal WPF way (an `InputBinding`/`KeyBinding`, or `AddKeyboardAccelerator` when the button lives in a [CommandBar](./command-bar)).

## See also

### Microsoft Learn

- [AppBarButton Class (WinRT)](https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.appbarbutton)

- [Command bar - Windows apps](https://learn.microsoft.com/en-us/windows/apps/design/controls/command-bar)

### Related controls

- [AppBarToggleButton](./appbar-toggle-button)

- [AppBarRepeatButton](./appbar-repeat-button)

- [AppBarSeparator](./appbar-separator)

- [CommandBar](./command-bar)

- [CommandBarFlyout](./command-bar-flyout)

- [MenuFlyout](./menu-flyout)
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
description: "A button that's styled for use in a CommandBar, and raises Click repeatedly while pressed and held."
---

# AppBarRepeatButton

AppBarRepeatButton is the same idea as [AppBarButton](./appbar-button), but built on WPF's native `RepeatButton` instead of `Button`: holding it down keeps raising **Click** on a timer, instead of only once. Use it in a [CommandBar](./command-bar) or [CommandBarFlyout](./command-bar-flyout) for commands that make sense to repeat while held, such as zoom in/out, volume up/down, or nudging a value.

- **Class**: [iNKORE.UI.WPF.Modern.Controls](..)[.AppBarRepeatButton](.)

- **Inheritance**: [Object](https://learn.microsoft.com/en-us/dotnet/api/system.object) → (...) → [ButtonBase](https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.primitives.buttonbase) → [RepeatButton](https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.primitives.repeatbutton) → [AppBarRepeatButton](.)

## Examples

### A basic AppBarRepeatButton

It's used exactly like [AppBarButton](./appbar-button): set **Label** and **Icon** instead of `Content`, and handle **Click**.

```xml
<ui:AppBarRepeatButton Click="ZoomIn_Click" Label="Zoom in">
<ui:AppBarRepeatButton.Icon>
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.ZoomIn}" />
</ui:AppBarRepeatButton.Icon>
</ui:AppBarRepeatButton>
```

```csharp
private void ZoomIn_Click(object sender, RoutedEventArgs e)
{
CurrentZoom = Math.Min(CurrentZoom + 0.1, 4.0);
}
```

While the button is held down, `Click` keeps firing, so `CurrentZoom` keeps increasing until the user releases the mouse or lifts their finger.

### Controlling the repeat timing

**Delay** and **Interval**, inherited from the native `RepeatButton`, control how long to wait before the first repeat and how often it repeats after that (both in milliseconds):

```xml
<ui:AppBarRepeatButton
Click="VolumeDown_Click"
Delay="400"
Interval="80"
Label="Volume down">
<ui:AppBarRepeatButton.Icon>
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.VolumeDown}" />
</ui:AppBarRepeatButton.Icon>
</ui:AppBarRepeatButton>
```

### In a CommandBar

AppBarRepeatButton participates in overflow and layout the same way [AppBarButton](./appbar-button) does, so it can go straight into a [CommandBar](./command-bar)'s primary or secondary commands:

```xml
<ui:CommandBar DefaultLabelPosition="Right">
<ui:AppBarRepeatButton Click="ZoomIn_Click" Label="Zoom in">
<ui:AppBarRepeatButton.Icon>
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.ZoomIn}" />
</ui:AppBarRepeatButton.Icon>
</ui:AppBarRepeatButton>
<ui:AppBarRepeatButton Click="ZoomOut_Click" Label="Zoom out">
<ui:AppBarRepeatButton.Icon>
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.ZoomOut}" />
</ui:AppBarRepeatButton.Icon>
</ui:AppBarRepeatButton>
</ui:CommandBar>
```

## Remarks

### There's no WinUI equivalent

Unlike [AppBarButton](./appbar-button), [AppBarToggleButton](./appbar-toggle-button), and [AppBarSeparator](./appbar-separator), AppBarRepeatButton isn't a port of a WinUI type, WinUI's `CommandBar` doesn't have a repeat-button command. This library adds it because WPF's `RepeatButton` already exists natively and repeat-while-held is a common toolbar need, so if you're cross-referencing against WinUI's docs, you won't find a matching page there.

### It's still an AppBar element

AppBarRepeatButton implements the same `ICommandBarElement` interface as the other AppBar controls, so it gets the same **IsCompact**, **LabelPosition**, and overflow handling when it's a [CommandBar](./command-bar) command. See [AppBarButton](./appbar-button)'s remarks on those, everything there applies here too.

### Command vs. Click for repeating actions

If you bind **Command** instead of handling **Click**, that command's `Execute` is what runs repeatedly, make sure it's cheap enough to call many times a second, or debounce/throttle the actual work it does.

## See also

### Microsoft Learn

- [RepeatButton Class (WPF)](https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.primitives.repeatbutton)

- [Command bar - Windows apps](https://learn.microsoft.com/en-us/windows/apps/design/controls/command-bar)

### Related controls

- [AppBarButton](./appbar-button)

- [AppBarToggleButton](./appbar-toggle-button)

- [AppBarSeparator](./appbar-separator)

- [CommandBar](./command-bar)
Loading