[英]How to get selected item from AutoSuggestBox in Windows Phone 8.1
[英]Strange results in AutoSuggestBox in Windows Phone 8.1
我試圖在Windows Phone 8.1 XAML應用程序中使用標准AutoSuggestBox
,但它的行為非常奇怪。
在一個簡單的演示中,我有收集
Items = new ObservableCollection<string>
{
"a",
"b",
"c",
"d"
};
和他在XAML中的AutoSuggestBox:
<AutoSuggestBox ItemsSource="{Binding Items}" />
問題是,無論我寫給AutoSuggestBox
是什么,我總是得到所有項目:
文檔說幾乎沒有,我沒有找到任何使用此控件的示例。
請嘗試以下代碼:
private void AutoSuggestBox_TextChanged(AutoSuggestBox sender,
AutoSuggestBoxTextChangedEventArgs args)
{
List<string> myList = new List<string>();
foreach (string myString in PreviouslyDefinedStringArray)
{
if (myString.Contains(sender.Text) == true)
{
myList.Add(myString);
}
}
sender.ItemsSource = myList;
}
這應該適用於WP 8.1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.