Search This Blog

Thursday, October 31, 2013

WPF RepeatButton

WPF > Controls  > ContentControl > RepeatButton

WPF RepeatButton raises its Click event repeatedly from the time it is pressed until it is released.

Properties
  • Interval: gets or sets the amount of time, in milliseconds, between repeats once repeating starts
  • Delay: gets or sets the amount of time, in milliseconds, the RepeatButton waits while it is pressed before it starts repeating
WPF RepeatButton Example:

XAML:

<Grid>
        <RepeatButton Margin="10,10,0,0" VerticalAlignment="Top"
              Delay="500" Interval="500"
              HorizontalAlignment="Left"                      
              x:Name="btnIncrease"  Width="352" Height="30" Click="GrowButton_Click">
            RepeatButton: Click on this button and keep mouse pressed
        </RepeatButton>
        <TextBlock x:Name="txt" HorizontalAlignment="Left" Margin="10,55,0,0" TextWrapping="Wrap" Text="TextBlock"
                   VerticalAlignment="Top" Height="18" Width="352" RenderTransformOrigin="0.5,0.5">
        </TextBlock>
</Grid>

C# Code:

public partial class MainWindow : Window
    {
        int k = 0;
        public MainWindow()
        {
            InitializeComponent();
        }
        private void GrowButton_Click(object sender, RoutedEventArgs e)
        {
            k += 1;
            txt.Text = k.ToString() ;
        }
    }