AutoSuggestBox在Windows Phone 8.1运行时应用程序中无法正常工作

时间:2015-02-16 08:45:15

标签: windows-phone-8 windows-phone-8.1

我在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";
        }

提前致谢:)

1 个答案:

答案 0 :(得分:0)

尝试在TextChanged事件中添加您想要的建议:

Strange results in AutoSuggestBox in Windows Phone 8.1,可以帮到你。

Reference