示例#1
0
#pragma warning disable CA1801 // Review unused parameters
        private void SearchQuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
        {
            if (args.ChosenSuggestion != null && args.ChosenSuggestion is DemoInfo)
            {
                this.viewModel.SelectDemo(args.ChosenSuggestion as DemoInfo);
            }
            else if (!string.IsNullOrEmpty(args.QueryText))
            {
                // Gets a collection of non-exact matches of the target item
                var suggestions = MainViewModel.SearchDemos(args.QueryText);
                if (suggestions.Count > 0)
                {
                    // By default, select the first demo from the suggestions
                    this.viewModel.SelectDemo(suggestions.FirstOrDefault());
                }
            }
        }
示例#2
0
 private void SearchTextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
 {
     if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
     {
         var suggestions = MainViewModel.SearchDemos(sender.Text);
         if (suggestions.Count > 0)
         {
             sender.ItemsSource  = suggestions;
             sender.ItemTemplate = this.Resources["SearchResultsItemTemplate"] as DataTemplate;
         }
         else
         {
             sender.ItemsSource  = new string[] { "No results found" };
             sender.ItemTemplate = null;
         }
     }
 }