WPF toolkit AutoCompleteBox
Posted Fred1987
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF toolkit AutoCompleteBox相关的知识,希望对你有一定的参考价值。
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="350" Width="525">
<Grid>
<controls:AutoCompleteBox ItemsSource="{Binding Names}" Height="120" BorderBrush="Black" BorderThickness="5" FontSize="50"/>
</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的主要内容,如果未能解决你的问题,请参考以下文章
WPF 使用 Microsoft.Toolkit.Wpf.UI.Controls 的 InkCanvas 时加上背景色和按钮方法
使用 Microsoft.Toolkit.Mvvm 和 Microsoft.Xaml.Behaviors.Wpf 将事件参数传递给命令
WPF 使用 Microsoft.Toolkit.Wpf.UI.Controls 的 InkCanvas 时加上背景色和按钮方法
.NET 4 WPF Datagrid 和 WPF Toolkit Datagrid 之间的差异