The following XAML code creates a RepeatButton control.
- <RepeatButton Margin="10,10,0,0" VerticalAlignment="Top"
- HorizontalAlignment="Left"
- Name="GrowButton" Width="80" Height="30">
- </RepeatButton>
Listing 1
The default property of a RepeatButton is Content. The code snippet in Listing 2 creates the same button as created by Listing 1.
- <RepeatButton Margin="10,10,0,0" VerticalAlignment="Top"
- HorizontalAlignment="Left"
- Name="GrowButton" Width="80" Height="30">
- Grow
- </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.
- <RepeatButton Margin="10,10,0,0" VerticalAlignment="Top"
- HorizontalAlignment="Left"
- Name="GrowButton" Width="80" Height="30"
- Delay="500" Interval="100" >
- Grow
- </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.
- <Button x:Name="DrawCircleButton" Height="40" Width="120"
- Canvas.Left="10" Canvas.Top="10"
- Content="Draw Circle"
- VerticalAlignment="Top"
- HorizontalAlignment="Left">
- Click="DrawCircleButton_Click"
- </Button>
Listing 4
The code for the click event handler looks as in following.
- private void GrowButton_Click(object sender, RoutedEventArgs e)
- {
- }