Rinktacular Rinktacular - 1 year ago 250
C# Question

Trouble Setting Up "Item Source" for AutoCompleteTextBox from WPF Extended Toolkit

I know that in the the base version of WPF, you can set up a combo box with an ItemSource for options in the drop down:

ComboBox box = new ComboBox();
box.ItemSource = List<string> exampleList;

I am using the WPF Extended Toolkit to attempt that same feature with the AutoCompleteTextBox, however there is no "Item Source" Property. I have been looking at examples online for the past few days but have yet to find an example where the suggestion list is generated. I have properly set up my XAML to include the ToolKit namespace and the actual textbox shows up fine:

<Window x:Class="complianceAuthApp.MainWindow"
Title="Authorization Submission App" Height="290" Width="747" Closing="Window_Closing" ResizeMode="CanMinimize">

However, I want to run a SQL query whenever the number of characters in the textbox reaches 3 or more:

public void getAutoTextBoxItemSource()

if (lastNameAutoTextBox.Text.Length < 3)

List<string> results = new List<string>();
SqlConnection cnn = new SqlConnection(ConfigurationManager["SQLQuery"].ConnectionString);
string sqlCommand = "SELECT TOP 10 ... ";

SQL.DataSet ds = new SQL.DataSet();
SQL.DataTable dtable = new SQL.DataTable();
SqlDataAdapter dscmd = new SqlDataAdapter(sqlCommand, cnn);

int t = await Task.Run(() => dscmd.Fill(dtable));
foreach (SQL.DataRow row in dtable.Rows)
results.Add(new string);

//If there WERE to be an ItemSource Property...


I can not seem to find an example that fits my needs and have spend the past few days trying to figure out how to implement my project in this way.

Answer Source

The control in your XAML is <xctk:AutoSelectTextBox. Xceed.Wpf.Toolkit.AutoSelectTextBox is a textbox which selects its text automatically when the user tabs into it. It's not an auto-complete textbox.

You need a different WPF Toolkit. Go to the Downloads page, download and install WPFToolkit.msi. It installs a raft of assemblies in C:\Program Files (x86)\WPF Toolkit\v3.5.50211.1\. So right click on "References" in your WPF project, select "Add Reference". In the dialog, click "Browse...", and browse to C:\Program Files (x86)\WPF Toolkit\v3.5.50211.1\. Select these two assemblies:


And Add them.

Then add this namespace to your XAML:


And you should be able to use toolkit:AutoCompleteBox

    ItemsSource="{Binding Items}"

There are other answers about this, but as far as I can tell they're incomplete and/or obsolete. I couldn't find one that said where the MSI puts the assemblies. One says you'll find a "Data Visualization" section in your Toolbox panel in VS. That may have been the case at some point, but it is not the case in VS 2015 with the version I just installed. YMMV, maybe.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download