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;
<Window x:Class="complianceAuthApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:complianceAuthApp"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
Title="Authorization Submission App" Height="290" Width="747" Closing="Window_Closing" ResizeMode="CanMinimize">
<grid>
...
<xctk:AutoSelectTextBox
Name="lastNameAutoTextBox"
AutoWordSelection="True"
BorderBrush="DarkGray"
AutoSelectBehavior="OnFocus"
Margin="21,35,586,193"/>
</Grid>
</Window>
public void getAutoTextBoxItemSource()
{
if (lastNameAutoTextBox.Text.Length < 3)
return;
List<string> results = new List<string>();
SqlConnection cnn = new SqlConnection(ConfigurationManager["SQLQuery"].ConnectionString);
string sqlCommand = "SELECT TOP 10 ... ";
cnn.Open();
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...
lastNameAutoTextBox.ItemSource=results;
}
}
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:
System.Windows.Controls.Input.Toolkit.dll
WPFToolkit.dll
And Add them.
Then add this namespace to your XAML:
xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
And you should be able to use toolkit:AutoCompleteBox
<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.