WPF Standard Control Demo App › RepeatButton

RepeatButton Inputs

RepeatButton keeps clicking while it is held down. WPF uses it for the arrows and the track of a ScrollBar and for the track of a Slider.

When the clicks repeat

RepeatButton derives from ButtonBase. Its ClickMode defaults to Press, so the first click comes when the mouse button goes down. Holding it down for about a second with Delay="300" and Interval="100" gave the first click right away, the second about Delay later, and the rest about every Interval (110 ms on the measuring machine), so do not count on Interval being exact. Releasing the button did not add a click. A bound Command ran once for every click; clamp the value in the command, or a spinner runs past its range.

The repetition stops when the pointer leaves the button: with the mouse button still held, there was no click while the pointer was outside, and IsPressed was False. Clicks resumed when the pointer came back. Holding Space also repeats. A single key-down event, with no key repeat from Windows, gave 8 clicks in a second. UI Automation’s Invoke gave one click.

case measured
default Delay / Interval (KeyboardDelay / KeyboardSpeed on this machine) 500 / 33 (1 / 31)
default ClickMode Press
Delay=300, Interval=100, mouse held for about 1 s: clicks while held / after release 8 / 0
first click after button down / second after the first 23 ms / 320 ms
gaps after that: min / median / max 108 ms / 110 ms / 111 ms
Command executions / Click events 8 / 8
held, moved off for 0.5 s, moved back for 0.5 s: clicks outside (IsPressed) / after returning 0 (False) / 4
Space held for 1 s, one key-down event (no OS key repeat): clicks while held / after release 8 / 0
UI Automation Invoke: clicks 1

Defaults, and clicks while the mouse button or Space is held. Measured on .NET 10 / Windows 11.

Delay and Interval come from the user’s keyboard settings

The defaults of Delay and Interval are not fixed numbers. On the measuring machine, where the Windows keyboard repeat delay setting is 1, Delay was 500; with the keyboard repeat rate setting at 31, Interval was 33. Set both explicitly if the speed matters.

A negative Delay set from code threw ArgumentException; 0 was accepted. Interval must be greater than 0: setting 0 from code threw ArgumentException.

An invalid bound value resets to the default

The demo app binds Delay and Interval to text boxes. A value that cannot be used does not keep the previous one. After "200", entering "-1", an empty string, or "abc" each set Delay to the default, 500. Entering "0" after "50" set Interval to the default, 33. Validate the values before they reach the button.

case measured
Delay = -1 / Delay = 0 set from code ArgumentException / no exception
Interval = 0 / Interval = 1 set from code ArgumentException / no exception
demo binding, Delay from TextBox.Text (in order) "200" -> 200, "-1" -> 500, "" -> 500, "abc" -> 500
demo binding, Interval from TextBox.Text (in order) "50" -> 50, "0" -> 33
RepeatButtons in a vertical ScrollBar template (their commands) LineUp, PageUp, PageDown, LineDown
RepeatButtons in a horizontal ScrollBar template (their commands) LineLeft, PageLeft, PageRight, LineRight
RepeatButtons in the Slider template (their commands) DecreaseLarge, IncreaseLarge

Invalid values, and the RepeatButtons in WPF’s own templates. Measured on .NET 10 / Windows 11.

Where WPF itself uses RepeatButton

A vertical ScrollBar has four RepeatButtons, with the LineUp, PageUp, PageDown, and LineDown commands; a horizontal one has LineLeft, PageLeft, PageRight, and LineRight. These are the two arrows and the track on each side of the thumb. A Slider has two, DecreaseLarge and IncreaseLarge, on each side of its thumb; it has no arrow buttons.

Trying it in the demo app

The RepeatButton page of the demo app, with the control list on the left and the first section, Delay / Interval

The RepeatButton page of the demo app binds Delay and Interval to two text boxes and shows the time of the last click. The “Show Code” link under the section displays its XAML. The following XAML is that section (RepeatButtonUsageControl.xaml), with the styles, the surrounding GroupBoxes, and the input behavior of the text boxes left out and the namespace declarations added:

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <TextBox x:Name="DelayTextBox" Text="100" />
  <TextBox x:Name="IntervalTextBox" Text="100" />

  <RepeatButton x:Name="RepeatButtonResult"
                Command="{Binding ClickCommand}"
                Content="Hold down"
                Delay="{Binding Text, ElementName=DelayTextBox}"
                Interval="{Binding Text, ElementName=IntervalTextBox}" />

  <TextBlock x:Name="ClickDateTimeTextBlock" Text="{Binding ClickDateTimeText}" />
</StackPanel>

Source code and how it was measured

Every behavior on this page was measured by running it on .NET 10 / Windows 11, using RepeatButtonDemoScene in this site’s screenshot tool. Holding the button was done with the real mouse over the measuring window. The keys were sent through WPF’s input manager, the same path as keys typed on a keyboard. Times and defaults are the values on the measuring machine.

View RepeatButton source code on GitHub →