我在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";
}
提前致谢:)
答案 0 :(得分:0)