Xaml windows 8.1中的AutoSuggestBox实现
我需要在windows 8.1应用程序中实现一个AutoSuggestBox。我的目标是有一个文本框,它建议并自动完成用户键入的文本Xaml windows 8.1中的AutoSuggestBox实现,xaml,autocomplete,windows-8.1,windows-applications,autosuggest,Xaml,Autocomplete,Windows 8.1,Windows Applications,Autosuggest,我需要在windows 8.1应用程序中实现一个AutoSuggestBox。我的目标是有一个文本框,它建议并自动完成用户键入的文本 作为一个新手,我对应用程序开发知之甚少。我也不熟悉数据绑定,这似乎是至关重要的。所以请简单一点。简单的代码隐藏示例 MainPage.xaml.cs public ObservableCollection<string> Items { get; private set; } public MainPage() {
作为一个新手,我对应用程序开发知之甚少。我也不熟悉数据绑定,这似乎是至关重要的。所以请简单一点。简单的代码隐藏示例 MainPage.xaml.cs
public ObservableCollection<string> Items { get; private set; }
public MainPage()
{
this.InitializeComponent();
Items = new ObservableCollection<string>
{
"test",
"new",
"to",
"test1"
};
}
private void autosuggest_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
List<string> myList = new List<string>();
foreach (string myString in Items)
{
if (myString.Contains(sender.Text) == true)
{
myList.Add(myString);
}
}
sender.ItemsSource = myList;
}
MainPage.xaml
<AutoSuggestBox x:Name="autosuggest" Foreground="White" TextChanged="autosuggest_TextChanged" />