Browse Source

Add delay to SearchBox.

pull/10/head
Daniel Grunwald 15 years ago
parent
commit
a0f22ed522
  1. 29
      ILSpy/Controls/SearchBox.cs
  2. 2
      ILSpy/MainWindow.xaml

29
ILSpy/Controls/SearchBox.cs

@ -21,6 +21,7 @@ using System.Windows; @@ -21,6 +21,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
namespace ICSharpCode.ILSpy.Controls
{
@ -40,6 +41,10 @@ namespace ICSharpCode.ILSpy.Controls @@ -40,6 +41,10 @@ namespace ICSharpCode.ILSpy.Controls
public static DependencyProperty HasTextProperty = DependencyProperty.Register("HasText", typeof(bool), typeof(SearchBox));
public static readonly DependencyProperty UpdateDelayProperty =
DependencyProperty.Register("UpdateDelay", typeof(TimeSpan), typeof(SearchBox),
new FrameworkPropertyMetadata(TimeSpan.FromMilliseconds(200)));
#endregion
#region Public Properties
@ -59,6 +64,11 @@ namespace ICSharpCode.ILSpy.Controls @@ -59,6 +64,11 @@ namespace ICSharpCode.ILSpy.Controls
private set { SetValue(HasTextProperty, value); }
}
public TimeSpan UpdateDelay {
get { return (TimeSpan)GetValue(UpdateDelayProperty); }
set { SetValue(UpdateDelayProperty, value); }
}
#endregion
#region Handlers
@ -72,10 +82,29 @@ namespace ICSharpCode.ILSpy.Controls @@ -72,10 +82,29 @@ namespace ICSharpCode.ILSpy.Controls
#region Overrides
DispatcherTimer timer;
protected override void OnTextChanged(TextChangedEventArgs e) {
base.OnTextChanged(e);
HasText = this.Text.Length > 0;
if (timer == null) {
timer = new DispatcherTimer();
timer.Tick += timer_Tick;
}
timer.Stop();
timer.Interval = this.UpdateDelay;
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
timer.Stop();
timer = null;
var textBinding = GetBindingExpression(TextProperty);
if (textBinding != null) {
textBinding.UpdateSource();
}
}
protected override void OnLostFocus(RoutedEventArgs e)

2
ILSpy/MainWindow.xaml

@ -131,7 +131,7 @@ @@ -131,7 +131,7 @@
<DockPanel>
<!-- Search bar -->
<controls:SearchBox DockPanel.Dock="Top" WatermarkText="Search" WatermarkColor="Gray" ToolTip="Search"
Text="{Binding FilterSettings.SearchTerm, UpdateSourceTrigger=PropertyChanged}" />
Text="{Binding FilterSettings.SearchTerm}" />
<!-- Tree View of assemblies and classes -->
<tv:SharpTreeView
Name="treeView"

Loading…
Cancel
Save