diff --git a/src/Avalonia.Controls/RepeatButton.cs b/src/Avalonia.Controls/RepeatButton.cs index a9ccb79fe1..482c45c8c0 100644 --- a/src/Avalonia.Controls/RepeatButton.cs +++ b/src/Avalonia.Controls/RepeatButton.cs @@ -12,6 +12,12 @@ namespace Avalonia.Controls public static readonly StyledProperty DelayProperty = AvaloniaProperty.Register(nameof(Delay), 100); + /// + /// Defines the property. + /// + public static readonly StyledProperty InitialDelayProperty = + AvaloniaProperty.Register(nameof(InitialDelay), 300); + private DispatcherTimer _repeatTimer; /// @@ -23,20 +29,39 @@ namespace Avalonia.Controls set { SetValue(DelayProperty, value); } } + /// + /// Gets or sets the amount of time, in milliseconds, to wait before repeating begins. + /// + public int InitialDelay + { + get { return GetValue(InitialDelayProperty); } + set { SetValue(InitialDelayProperty, value); } + } + private void StartTimer() { if (_repeatTimer == null) { _repeatTimer = new DispatcherTimer(); - _repeatTimer.Tick += (o, e) => OnClick(); + _repeatTimer.Tick += RepeatTimerOnTick; } if (_repeatTimer.IsEnabled) return; - _repeatTimer.Interval = TimeSpan.FromMilliseconds(Delay); + _repeatTimer.Interval = TimeSpan.FromMilliseconds(InitialDelay); _repeatTimer.Start(); } + private void RepeatTimerOnTick(object sender, EventArgs e) + { + var interval = TimeSpan.FromMilliseconds(Delay); + if (_repeatTimer.Interval != interval) + { + _repeatTimer.Interval = interval; + } + OnClick(); + } + private void StopTimer() { _repeatTimer?.Stop();