【发布时间】:2015-02-16 23:46:28
【问题描述】:
我在 windows phone 8(Silverlight 应用程序)中使用了 AutoCompleteBox,它运行良好,但在 autosuggestbox 中我找不到 ItemFilter 属性,即使我使用 TextChanged 事件它也没有给出相关建议。我的代码如下。
Xaml 代码:
<AutoSuggestBox x:Name="suggestions" HorizontalAlignment="Left" Margin="52,62,0,0"
ItemsSource="{Binding }" VerticalAlignment="Top"
Width="296" TextChanged="suggestions_TextChanged"
SuggestionChosen="suggestions_SuggestionChosen"/>
C#代码:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
suggestions.ItemsSource = Suggestions;
}
private void suggestions_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
Suggestions.Clear();
Suggestions.Add("Nambukarthy Raveendran");
Suggestions.Add("Jeyanthan Periyasami");
Suggestions.Add("Vijay Selvamm");
Suggestions.Add("Ashraf Ali");
List<string> myList = new List<string>();
foreach (string myString in Suggestions)
{
if (myString.Contains(sender.Text) == true)
{
myList.Add(myString);
}
}
sender.ItemsSource = myList;
}
}
private void suggestions_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
suggestions.Text = "Choosen";
}
提前致谢:)
【问题讨论】:
标签: windows-phone-8 windows-phone-8.1