-api-id | -api-type |
---|---|
T:Windows.UI.Xaml.Controls.Primitives.RepeatButton |
winrt class |
Represents a control that raises its Click event repeatedly when it is pressed and held.
<RepeatButton .../>
-or-
<RepeatButton>
singleObject
</RepeatButton>
-or-
<RepeatButton ...>stringContent</RepeatButton>
A RepeatButton is a button that raises Click events repeatedly from the time it is pressed until it is released. Set the Delay property to specify the time that the RepeatButton waits after it is pressed before it starts repeating the click action. Set the Interval property to specify the time between repetitions of the click action. Times for both properties are specified in milliseconds.
Tip
For more info, design guidance, and code examples, see Buttons.
If you have the WinUI 2 Gallery app installed, click here to open the app and see the RepeatButton in action.
The following example shows two RepeatButton controls whose respective Click events are used to increase and decrease the value shown in a TextBlock.
<StackPanel>
<RepeatButton Width="100" Delay="500" Interval="100" Click="Increase_Click">Increase</RepeatButton>
<RepeatButton Width="100" Delay="500" Interval="100" Click="Decrease_Click">Decrease</RepeatButton>
<TextBlock x:Name="clickTextBlock" Text="Number of Clicks:"/>
</StackPanel>
private static int _clicks = 0;
private void Increase_Click(object sender, RoutedEventArgs e)
{
_clicks += 1;
clickTextBlock.Text = "Number of Clicks: " + _clicks;
}
private void Decrease_Click(object sender, RoutedEventArgs e)
{
if(_clicks > 0)
{
_clicks -= 1;
clickTextBlock.Text = "Number of Clicks: " + _clicks;
}
}