Introduction
The RepeatButton is a Silverlight control which does an action repeatedly from the time a user presses it till the time it is released.
OverviewTo demonstrate the common use of the RepeatButton I’ll give an example:
XAML:
<UserControl x:Class="RepeatButton2.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="200" Height="100">
<Canvas x:Name="cnvLayoutRoot" Background="White">
<TextBlock x:Name="tblText" Canvas.Top="20" Canvas.Left="30" Text="Not clicked yet."></TextBlock>
<RepeatButton x:Name="rbtnTest" Click="rbtnTest_Click" Delay="1000" Interval="500"Canvas.Top="60" Canvas.Left="30" Content="Show the time"></RepeatButton>
</Canvas>
</UserControl>private void rbtnTest_Click( object sender, RoutedEventArgs e )
{
this.tblText.Text = DateTime.Now.ToString( System.Globalization.CultureInfo.InvariantCulture );
}An important property is the Interval. Its value is in milliseconds and it determines the interval between the occurrences of theClick event while the button is being pressed. The default is 250.
The Delay property determines the time in milliseconds between the pressing of the button and the time when the button starts repeating the Click event. The default is 250.
If you want to see how you can use the ClickMode property visit the Button Controls Article. This member is inherited from theButtonBase class. The example there is with a Button but it is the same with a RepeatButton.
Issues
Just imagine that we want the RepeatButton to wait 10 seconds before it starts showing the time. To do that we set the Delayproperty to 10000 like this:
<RepeatButton x:Name="rbtnTest" Click="rbtnTest_Click" Delay="10000" Interval="500"Canvas.Top="60" Canvas.Left="30" Content="Show the time"></RepeatButton>
The expected behavior is that when the button is pressed it waits 10 seconds and then it shows the time. This isn’t exactly what happens. When the button is pressed the current date and time show. A pause of 10 seconds follows and after it the TextBlockbegins to update. It seems that there is one parasitic Click event. Maybe it is inherited from the ButtonBase class. Check yourself:<RepeatButton x:Name="rbtnTest" ClickMode="Release" Click="rbtnTest_Click" Delay="10000"Interval="500" Canvas.Top="60" Canvas.Left="30" Content="Show the time"></RepeatButton>
In this case the extra Click event will occur when the button is released:<RepeatButton x:Name="rbtnTest" ClickMode="Hover" Click="rbtnTest_Click" Delay="10000"Interval="500" Canvas.Top="60" Canvas.Left="30" Content="Show the time"></RepeatButton>
Here is the result:Example
Martin Mihaylov’s demo about MultiscaleImage uses repeat buttons to zoom in and out: MultiscaleImage Demo
Conclusion
This article is just a brief description of the key features of the RepeatButton control. It targets the developer who has just started withthe new Silverlight 2 controls. Any comments are welcome.
Download Source Code











