WPF: AutoFill TextBox, ... again

This other SO question asks about autocomplete text field in WPF. Several people have created them, and one of the answers given there offers this article about code design.

But I did not find a single WPF autocomplete text field that can be compared with the WinForms autocomplete text field. Sample project code works, sort of ...

alt text

...but

  • it is not structured as a reusable control or DLL. This is the code I need to embed in every application.
  • Only works with directories. it has no properties to set whether the autocomplete source is only file system directories, or file system files, or .... etc. Of course, I could write code for this, but ... I would prefer to use another code already written.
  • it has no properties for setting the size of the popup, etc.
  • there is a popup with a list of possible completions. When navigating through this list, the text field does not change. Entering a character that is in focus in the list does not update the text field.
  • moving the focus from the list does not lead to the disappearance of the pop-up list. This confuses.

So my question is:

* Does anyone have a FREE WPF autocomplete text box that works and provides a quality user interface? *




ANSWER

Here is how I did it:

+0.0. get WPF toolkit

0.1. run MSI for WPF Toolkit

0.2. In Visual Studio, drag from the toolbar, in particular from the Data Visualization group, into the user interface designer. It looks like this in the VS toolbox:

alt text

If you do not want to use a designer, make xaml manually. It looks like this:




<toolkit:AutoCompleteBox ToolTip="Enter the path of an assembly." x:Name="tbAssembly" Height="27" Width="102" Populating="tbAssembly_Populating" /> 

... where the toolbox namespace is displayed as follows:

 xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" 



0.3. Specify the code for the Populating event. Here is what I used:




 private void tbAssembly_Populating(object sender, System.Windows.Controls.PopulatingEventArgs e) { string text = tbAssembly.Text; string dirname = Path.GetDirectoryName(text); if (Directory.Exists(Path.GetDirectoryName(dirname))) { string[] files = Directory.GetFiles(dirname, "*.*", SearchOption.TopDirectoryOnly); string[] dirs = Directory.GetDirectories(dirname, "*.*", SearchOption.TopDirectoryOnly); var candidates = new List<string>(); Array.ForEach(new String[][] { files, dirs }, (x) => Array.ForEach(x, (y) => { if (y.StartsWith(dirname, StringComparison.CurrentCultureIgnoreCase)) candidates.Add(y); })); tbAssembly.ItemsSource = candidates; tbAssembly.PopulateComplete(); } } 



It works the way you expect. He feels professional. There are no anomalies that the codeproject control exhibits. Here's what it looks like:

alt text




Thanks to Matt for pointing to the WPF toolkit.

+45
autocomplete wpf textbox
Feb 26 2018-10-12T00
source share
5 answers

AutoCompleteBox is included in the latest WPF Toolkit folder. This is a free set of controls from Microsoft, some of which will be included in .NET 4.

Jeff Wilcox - AutoCompleteBox Presentation

+32
Feb 26 2018-10-10T00 00
source share

Here is how I did it:

0.1. run MSI for WPF Toolkit

0.2. In Visual Studio, drag from the toolbar, in particular from the Data Visualization group, into the user interface designer. It looks like this in the VS toolbox:

alt text

Or do it manually xaml. It looks like this:




 <toolkit:AutoCompleteBox ToolTip="Enter the path of an assembly." x:Name="tbAssembly" Height="27" Width="102" Populating="tbAssembly_Populating" /> 

... where the toolbox namespace is displayed as follows:

 xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" 



0.3. Specify the code for the Populating event. Here is what I used:




 private void tbAssembly_Populating(object sender, System.Windows.Controls.PopulatingEventArgs e) { string text = tbAssembly.Text; string dirname = Path.GetDirectoryName(text); if (Directory.Exists(Path.GetDirectoryName(dirname))) { string[] files = Directory.GetFiles(dirname, "*.*", SearchOption.TopDirectoryOnly); string[] dirs = Directory.GetDirectories(dirname, "*.*", SearchOption.TopDirectoryOnly); var candidates = new List<string>(); Array.ForEach(new String[][] { files, dirs }, (x) => Array.ForEach(x, (y) => { if (y.StartsWith(dirname, StringComparison.CurrentCultureIgnoreCase)) candidates.Add(y); })); tbAssembly.ItemsSource = candidates; tbAssembly.PopulateComplete(); } } 



Thanks to Matt for pointing to the WPF toolkit.

+17
Feb 26 '10 at 2:00
source share

I use Intellibox in my own project. http://intellibox.codeplex.com/

I find its use of the Provider pattern to search very intuitive.

The answer to the rake gives an example of how to use it, and, as he points out, he saw some development at the end of last year (although this is good after the last time I used it).

+2
Jul 19 '11 at 4:00
source share

Mindscape also provides 3 free controls , including the Autocomplete WPF text box.

http://intellibox.codeplex.com/ seems to have been updated most recently since October 1, 2013 and contains a single control. I would add an answer to Troy as a comment, but not enough reputation. I almost ignored this because of this comment.

Documentation usage example:

  <auto:Intellibox ResultsHeight="80" ExplicitlyIncludeColumns="True" Name="lightspeedBox" DisplayedValueBinding="{Binding Product_Name}" SelectedValueBinding="{Binding Product_Id}" DataProvider="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=LinqToEntitiesProvider}" Height="26" Margin="12,26,12,0" VerticalAlignment="Top"> <auto:Intellibox.Columns> <auto:IntelliboxColumn DisplayMemberBinding="{Binding Product_Name}" Width="150" Header="Product Name" /> <auto:IntelliboxColumn DisplayMemberBinding="{Binding Unit_Price}" Width="75" Header="Unit Price" /> <auto:IntelliboxColumn DisplayMemberBinding="{Binding Suppliers.Company_Name}" Width="125" Header="Supplier" /> </auto:Intellibox.Columns> </auto:Intellibox> 
+2
May 2 '14 at 17:34
source share

You can try WPF Auto Complete TextBox in CodePlex here: https://wpfautocomplete.codeplex.com/

+2
Jul 29 '14 at 11:29
source share



All Articles