A Repeat Button is a button that initiates click events repeatedly from the time it is pressed until it is released.
Step 1: Open a blank app and add a Repeat Button and a Progress Bar control either from the toolbox or by copying the following XAML code into your grid.
- <StackPanel Margin="10,40,0,0">
- <TextBlock Text="Repeat Button" FontSize="20"></TextBlock>
- <StackPanel Orientation="Horizontal">
- <RepeatButton Name="myRepeatButton" Delay="500" Interval="100" Content="Click & Hold" Height="40" Width="120" Click="myRepeatButton_Click"></RepeatButton>
- <ProgressBar Name="myBar" Width="200" Height="8" Margin="10,0,0,0"></ProgressBar>
- </StackPanel>
- </StackPanel>
Set the Delay property to specify the time that the Repeat Button 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. The time for both properties are specified in milliseconds.
Step 2: Copy and paste the following code to the cs page to handle the events generated on clicking.
- private void myRepeatButton_Click(object sender, RoutedEventArgs e)
- {
- myBar.Value++;
- }
Step 3: Run your application and test yourself.