Add search input delay of 200ms
This commit is contained in:
@ -7,6 +7,7 @@ using System.Linq;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Threading;
|
||||||
using Xceed.Wpf.Toolkit;
|
using Xceed.Wpf.Toolkit;
|
||||||
|
|
||||||
namespace Elwig.Windows {
|
namespace Elwig.Windows {
|
||||||
@ -225,6 +226,22 @@ namespace Elwig.Windows {
|
|||||||
UpdateComboBox(ortInput);
|
UpdateComboBox(ortInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static void InitializeDelayTimer(TextBox tb, Action<object, TextChangedEventArgs> handler) {
|
||||||
|
var timer = new DispatcherTimer {
|
||||||
|
Interval = TimeSpan.FromMilliseconds(250)
|
||||||
|
};
|
||||||
|
timer.Tick += (object? sender, EventArgs evt) => {
|
||||||
|
timer.Stop();
|
||||||
|
var (oSender, oEvent) = ((object, TextChangedEventArgs))timer.Tag;
|
||||||
|
handler(oSender, oEvent);
|
||||||
|
};
|
||||||
|
tb.TextChanged += (object sender, TextChangedEventArgs evt) => {
|
||||||
|
timer.Stop();
|
||||||
|
timer.Tag = (sender, evt);
|
||||||
|
timer.Start();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
protected bool InputTextChanged(TextBox input, Func<TextBox, bool, ValidationResult> checker) {
|
protected bool InputTextChanged(TextBox input, Func<TextBox, bool, ValidationResult> checker) {
|
||||||
return InputTextChanged(input, (tb, required, ctx) => checker(tb, required));
|
return InputTextChanged(input, (tb, required, ctx) => checker(tb, required));
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,9 @@ namespace Elwig.Windows {
|
|||||||
Timer = new DispatcherTimer();
|
Timer = new DispatcherTimer();
|
||||||
Timer.Tick += new EventHandler(OnSecondPassed);
|
Timer.Tick += new EventHandler(OnSecondPassed);
|
||||||
Timer.Interval = new TimeSpan(0, 0, 1);
|
Timer.Interval = new TimeSpan(0, 0, 1);
|
||||||
|
|
||||||
|
InitializeDelayTimer(SearchInput, SearchInput_TextChanged);
|
||||||
|
SearchInput.TextChanged -= SearchInput_TextChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeliveryAdminWindow(bool receipt) : this() {
|
public DeliveryAdminWindow(bool receipt) : this() {
|
||||||
|
@ -50,6 +50,9 @@ namespace Elwig.Windows {
|
|||||||
(PhoneNr9TypeInput, PhoneNr9Input, PhoneNr9CommentInput),
|
(PhoneNr9TypeInput, PhoneNr9Input, PhoneNr9CommentInput),
|
||||||
};
|
};
|
||||||
foreach (var input in PhoneNrInputs) input.Item1.ItemsSource = PhoneNrTypes;
|
foreach (var input in PhoneNrInputs) input.Item1.ItemsSource = PhoneNrTypes;
|
||||||
|
|
||||||
|
InitializeDelayTimer(SearchInput, SearchInput_TextChanged);
|
||||||
|
SearchInput.TextChanged -= SearchInput_TextChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Window_Loaded(object sender, RoutedEventArgs evt) {
|
private void Window_Loaded(object sender, RoutedEventArgs evt) {
|
||||||
|
Reference in New Issue
Block a user