XAML RepeatButton Code Example

The <RepeatButton> element of XAML represents a repeat button. The code example shows how to use XAML RepeatButton in a WPF app.

The following XAML code creates a RepeatButton control.

  1. <RepeatButton Margin="10,10,0,0" VerticalAlignment="Top"   
  2.    HorizontalAlignment="Left"   
  3.    Name="GrowButton" Width="80" Height="30">  
  4. </RepeatButton>  
Listing 1
 
Note: This article has moved here: Working with a RepeatButton control using XAML and C# 

The default property of a RepeatButton is Content. The code snippet in Listing 2 creates the same button as created by Listing 1.
  1. <RepeatButton Margin="10,10,0,0" VerticalAlignment="Top"   
  2.    HorizontalAlignment="Left"   
  3.    Name="GrowButton" Width="80" Height="30">  
  4.    Grow  
  5. </RepeatButton>  
Listing 2

The output looks as in Figure 1.


 
Figure 1

The RepeatButton control has two important properties, Delay and Interval, that separate it from a normal button.
 
A RepeatButton is a button that fires Click events repeatedly when it is pressed and held. The rate and aspects of repeating are determined by the Delay and Interval properties that the control exposes.

The code snippet in Listing 3 sets the Delay and Interval properties.
  1. <RepeatButton Margin="10,10,0,0" VerticalAlignment="Top"   
  2.    HorizontalAlignment="Left"   
  3.    Name="GrowButton" Width="80" Height="30"   
  4.    Delay="500" Interval="100" >  
  5.    Grow  
  6. </RepeatButton>  
Listing 3

The Click attribute of a RepeatButton element adds the click event handler and it keeps firing the event for the given Interval and delay values. The code in Listing 4 adds the click event handler for a Button.
  1. <Button x:Name="DrawCircleButton" Height="40" Width="120"   
  2.         Canvas.Left="10" Canvas.Top="10"   
  3.         Content="Draw Circle"  
  4.         VerticalAlignment="Top"   
  5.         HorizontalAlignment="Left">  
  6. Click="DrawCircleButton_Click"  
  7. </Button>  
Listing 4

The code for the click event handler looks as in following.
  1. private void GrowButton_Click(object sender, RoutedEventArgs e)  
  2. {  
  3. }  
Visit this complete tutorial here: Working with a RepeatButton control using XAML and C#