Checked Http://www.broculos.net/2014/04/wpf-autocompletebox-autocomplete-text.html#.WGNnq4N95aQ.
1.Search WPF Toolkit in Nuget and install;
View:
<window x:class= "Wpfapplication28.mainwindow"
Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns:controls= "Clr-namespace:system.windows.controls;assembly=system.windows.controls.input.toolkit"
Title= "MainWindow" height= "width=" 525 ">
<Grid>
<controls:autocompletebox itemssource= "{Binding Names}" height= "" borderbrush= "Black" borderthickness= "5" Fontsize= "/>"
</Grid>
</Window>
Xaml.cs:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Windows;
Using System.Windows.Controls;
Using System.Windows.Data;
Using System.Windows.Documents;
Using System.Windows.Input;
Using System.Windows.Media;
Using System.Windows.Media.Imaging;
Using System.Windows.Navigation;
Using System.Windows.Shapes;
Namespace WpfApplication28
{
<summary>
Interaction Logic for MainWindow.xaml
</summary>
public partial class Mainwindow:window
{
Public MainWindow ()
{
InitializeComponent ();
This. DataContext = new Acbviewmodel ();
}
}
}
Vm:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Collections.ObjectModel;
Using System.ComponentModel;
Namespace WpfApplication28
{
Class acbviewmodel:inotifypropertychanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged (String propertyname)
{
if (propertychanged!=null)
{
PropertyChanged (This, new PropertyChangedEventArgs (PropertyName));
}
}
private observablecollection<string> names;
Public observablecollection<string> Names
{
Get
{
return names;
}
Set
{
names = value;
OnPropertyChanged ("Names");
}
}
Public Acbviewmodel ()
{
list<string> nameslist = new list<string> ();
Nameslist.add ("ST");
Nameslist.add ("ZTT");
Nameslist.add ("LY");
Nameslist.add ("Wyq");
Nameslist.add ("ZCQ");
Nameslist.add ("HT");
Names = new observablecollection<string> (nameslist);
}
}
}
WPF Toolkit Autocompletebox