Skip to content

Commit c1be9bb

Browse files
Clean-up usage of the sample slider value in the Debounce samples
1 parent 86e6d96 commit c1be9bb

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

components/Extensions/samples/Dispatcher/KeyboardDebounceSample.xaml.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,17 @@ public KeyboardDebounceSample()
2626

2727
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
2828
{
29-
var interval = this.GeneratedPropertyMetadata?.FirstOrDefault(vm => vm.Name == "Interval")?.Value as double?;
30-
31-
if (sender is TextBox textBox && interval != null)
29+
if (sender is TextBox textBox)
3230
{
3331
_debounceTimer.Debounce(() =>
3432
{
3533
ResultText.Text = textBox.Text;
3634
},
3735
//// i.e. if another keyboard press comes in within 120ms of the last, we'll wait before we fire off the request
38-
interval: TimeSpan.FromMilliseconds(interval.Value),
36+
interval: TimeSpan.FromMilliseconds(Interval),
3937
//// If we're blanking out or the first character type, we'll start filtering immediately instead to appear more responsive.
4038
//// We want to switch back to trailing as the user types more so that we still capture all the input.
4139
immediate: textBox.Text.Length <= 1);
42-
4340
}
4441
}
4542
}

components/Extensions/samples/Dispatcher/MouseDebounceSample.xaml.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,12 @@ public MouseDebounceSample()
2828

2929
private void Button_Click(object sender, RoutedEventArgs e)
3030
{
31-
var interval = this.GeneratedPropertyMetadata?.FirstOrDefault(vm => vm.Name == "Interval")?.Value as double?;
32-
33-
if (interval != null)
34-
{
35-
_debounceTimer.Debounce(() =>
36-
{
37-
ResultText.Text = $"You hit the button {++_count} times!";
38-
},
39-
interval: TimeSpan.FromMilliseconds(interval.Value),
40-
// By being on the leading edge, we ignore inputs past the first for the duration of the interval
41-
immediate: true);
42-
}
31+
_debounceTimer.Debounce(() =>
32+
{
33+
ResultText.Text = $"You hit the button {++_count} times!";
34+
},
35+
interval: TimeSpan.FromMilliseconds(Interval),
36+
// By being on the leading edge, we ignore inputs past the first for the duration of the interval
37+
immediate: true);
4338
}
4439
}

0 commit comments

Comments
 (0)