WPF Standard Control Demo App › RepeatButton

RepeatButton Inputs

RepeatButton is a button that continuously fires Click events while it is held down. It is particularly useful for implementing increment/decrement buttons or scroll controls where repeated action is needed without releasing the mouse button.

Overview

The WPF RepeatButton control extends the standard ButtonBase with auto-repeat behavior. While a regular Button fires its Click event exactly once per mouse-press-release cycle, RepeatButton fires Click repeatedly at a configurable rate for as long as the mouse button (or touch contact) is held down. This makes it the natural choice for controls that need continuous incremental updates.

The repeat timing is governed by two properties: Delay and Interval. When the button is first pressed, the initial Click fires immediately. WPF then waits for Delay milliseconds before starting the repeat sequence. After that initial pause, subsequent Click events fire every Interval milliseconds until the button is released. Both default to 250 ms, matching standard Windows system repeat settings.

RepeatButton is the building block for the scroll arrows inside ScrollBar and the up/down arrows in Slider. When you need to build a custom numeric input spinner or a custom scroll control, RepeatButton provides the repeat-fire mechanism out of the box without any timer code in your ViewModel.

Like all ButtonBase-derived controls, RepeatButton supports the Command and CommandParameter properties for MVVM binding, allowing the repeated action to be encapsulated in an ICommand implementation. The command is executed on each repeated Click event, enabling clean separation of UI logic.

Screen Preview

repeatbutton demo screen

Demonstrated Properties

The following properties are demonstrated interactively in the WPF Standard Control Demo App. Each property can be configured in real time within the app to observe its behavior.

Property Values Description
Delay int (ms, default: 250) Use this to tune how quickly the repeat sequence starts after the initial press, giving users a natural "intentional hold" window before the button fires repeatedly. Increasing the value (e.g., 400โ€“500 ms) reduces accidental over-increments when users just want a single click. Decreasing it makes the repeat feel more immediate. Pitfall: Setting Delay to an extremely short value (below 50 ms) can cause the repeat sequence to begin so quickly that on slower or heavily loaded machines the initial single-click intent is skipped entirely and the value jumps by multiple steps. Aim for 200โ€“500 ms to match natural user expectations.
Interval int (ms, default: 250) Use this to control how fast the value changes once the repeat sequence is running. A shorter interval (e.g., 100 ms) produces faster acceleration, good for coarse adjustments like page scrolling. A longer interval (e.g., 300โ€“500 ms) is better for fine-grained inputs like pixel-level positioning. Delay and Interval work together โ€” Delay governs the initial pause and Interval governs the ongoing rate. Pitfall: Setting Interval below 50 ms means the command can fire 20+ times per second. If the Click handler or ICommand performs non-trivial work (UI redraws, database writes, heavy calculations), the UI thread will become overloaded. Keep the handler lightweight and consider throttling if you need to support very short intervals.

XAML Example

A simple numeric spinner using two RepeatButtons to increment and decrement a value:

<StackPanel Orientation="Horizontal">
  <RepeatButton Content="▼" Width="24" Delay="300" Interval="100"
               Command="{Binding DecrementCommand}" />
  <TextBox Width="60" Text="{Binding Value}" TextAlignment="Center" />
  <RepeatButton Content="▲" Width="24" Delay="300" Interval="100"
               Command="{Binding IncrementCommand}" />
</StackPanel>

Common Use Cases

Tips and Best Practices

Related Controls

Source Code

The source code for this demo screen is available on GitHub. Use the built-in code view buttons in the app to see the exact XAML for each property.

View RepeatButton source code on GitHub →