diff --git a/src/Avalonia.Controls/RepeatButton.cs b/src/Avalonia.Controls/RepeatButton.cs index a9ccb79fe1..07a1e82638 100644 --- a/src/Avalonia.Controls/RepeatButton.cs +++ b/src/Avalonia.Controls/RepeatButton.cs @@ -6,17 +6,32 @@ namespace Avalonia.Controls { public class RepeatButton : Button { + /// + /// Defines the property. + /// + public static readonly StyledProperty IntervalProperty = + AvaloniaProperty.Register(nameof(Interval), 100); + /// /// Defines the property. /// public static readonly StyledProperty DelayProperty = - AvaloniaProperty.Register(nameof(Delay), 100); + AvaloniaProperty.Register(nameof(Delay), 300); private DispatcherTimer _repeatTimer; /// /// Gets or sets the amount of time, in milliseconds, of repeating clicks. /// + public int Interval + { + get { return GetValue(IntervalProperty); } + set { SetValue(IntervalProperty, value); } + } + + /// + /// Gets or sets the amount of time, in milliseconds, to wait before repeating begins. + /// public int Delay { get { return GetValue(DelayProperty); } @@ -28,7 +43,7 @@ namespace Avalonia.Controls if (_repeatTimer == null) { _repeatTimer = new DispatcherTimer(); - _repeatTimer.Tick += (o, e) => OnClick(); + _repeatTimer.Tick += RepeatTimerOnTick; } if (_repeatTimer.IsEnabled) return; @@ -37,6 +52,16 @@ namespace Avalonia.Controls _repeatTimer.Start(); } + private void RepeatTimerOnTick(object sender, EventArgs e) + { + var interval = TimeSpan.FromMilliseconds(Interval); + if (_repeatTimer.Interval != interval) + { + _repeatTimer.Interval = interval; + } + OnClick(); + } + private void StopTimer() { _repeatTimer?.Stop();