diff --git a/Samples/XamlAutoSuggestBox/cpp/Scenario1.xaml.cpp b/Samples/XamlAutoSuggestBox/cpp/Scenario1.xaml.cpp index e9b48142..b288aed9 100644 --- a/Samples/XamlAutoSuggestBox/cpp/Scenario1.xaml.cpp +++ b/Samples/XamlAutoSuggestBox/cpp/Scenario1.xaml.cpp @@ -42,6 +42,11 @@ void Scenario1::asb_TextChanged(AutoSuggestBox^ sender, AutoSuggestBoxTextChange sender->ItemsSource = ref new Vector(matchingContacts); } + + if (args->Reason != AutoSuggestionBoxTextChangeReason::SuggestionChosen) + { + rootPage->NotifyUser("", NotifyType::StatusMessage); + } } /// @@ -55,6 +60,8 @@ void Scenario1::asb_TextChanged(AutoSuggestBox^ sender, AutoSuggestBoxTextChange /// and also ChosenSuggestion, which is only non-null when a user selects an item in the list. void Scenario1::asb_QuerySubmitted(AutoSuggestBox^ sender, AutoSuggestBoxQuerySubmittedEventArgs^ args) { + rootPage->NotifyUser("", NotifyType::StatusMessage); + if (args->ChosenSuggestion != nullptr) { // User selected an item, take an action on it here @@ -71,17 +78,16 @@ void Scenario1::asb_QuerySubmitted(AutoSuggestBox^ sender, AutoSuggestBoxQuerySu } /// -/// This event gets fired as the user keys through the list, or taps on a suggestion. -/// This allows you to change the text in the TextBox to reflect the item in the list. -/// Alternatively you can use TextMemberPath. +/// This event is raised as the user keys through the list, or taps on a suggestion. +/// The AutoSuggestBox.TextMemberPath property controls what text appears in the TextBox. +/// You could use this event to trigger a prefetch of the suggestion. /// /// The AutoSuggestBox that fired the event. /// The args contain SelectedItem, which contains the data item of the item that is currently highlighted. void Scenario1::asb_SuggestionChosen(AutoSuggestBox^ sender, AutoSuggestBoxSuggestionChosenEventArgs^ args) { auto contact = safe_cast(args->SelectedItem); - - sender->Text = contact->DisplayName; + rootPage->NotifyUser("Suggestion chosen: " + contact->DisplayName, NotifyType::StatusMessage); } /// diff --git a/Samples/XamlAutoSuggestBox/cpp/Scenario1.xaml.h b/Samples/XamlAutoSuggestBox/cpp/Scenario1.xaml.h index 581be309..1ebc0239 100644 --- a/Samples/XamlAutoSuggestBox/cpp/Scenario1.xaml.h +++ b/Samples/XamlAutoSuggestBox/cpp/Scenario1.xaml.h @@ -23,9 +23,9 @@ namespace SDKTemplate public: Scenario1(); - protected: - private: + MainPage^ rootPage = MainPage::Current; + void asb_TextChanged(Windows::UI::Xaml::Controls::AutoSuggestBox^ sender, Windows::UI::Xaml::Controls::AutoSuggestBoxTextChangedEventArgs^ args); void asb_QuerySubmitted(Windows::UI::Xaml::Controls::AutoSuggestBox^ sender, Windows::UI::Xaml::Controls::AutoSuggestBoxQuerySubmittedEventArgs^ args); void asb_SuggestionChosen(Windows::UI::Xaml::Controls::AutoSuggestBox^ sender, Windows::UI::Xaml::Controls::AutoSuggestBoxSuggestionChosenEventArgs^ args); diff --git a/Samples/XamlAutoSuggestBox/cs/Scenario1.xaml.cs b/Samples/XamlAutoSuggestBox/cs/Scenario1.xaml.cs index 90817586..a4ddbcd2 100644 --- a/Samples/XamlAutoSuggestBox/cs/Scenario1.xaml.cs +++ b/Samples/XamlAutoSuggestBox/cs/Scenario1.xaml.cs @@ -53,6 +53,11 @@ namespace SDKTemplate sender.ItemsSource = matchingContacts.ToList(); } + + if (args.Reason != AutoSuggestionBoxTextChangeReason.SuggestionChosen) + { + rootPage.NotifyUser("", NotifyType.StatusMessage); + } } /// @@ -66,6 +71,8 @@ namespace SDKTemplate /// and also ChosenSuggestion, which is only non-null when a user selects an item in the list. private void asb_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) { + rootPage.NotifyUser("", NotifyType.StatusMessage); + if (args.ChosenSuggestion != null) { // User selected an item, take an action on it here @@ -82,17 +89,16 @@ namespace SDKTemplate } /// - /// This event gets fired as the user keys through the list, or taps on a suggestion. - /// This allows you to change the text in the TextBox to reflect the item in the list. - /// Alternatively you can use TextMemberPath. + /// This event is raised as the user keys through the list, or taps on a suggestion. + /// The AutoSuggestBox.TextMemberPath property controls what text appears in the TextBox. + /// You could use this event to trigger a prefetch of the suggestion. /// /// The AutoSuggestBox that fired the event. /// The args contain SelectedItem, which contains the data item of the item that is currently highlighted. private void asb_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args) { var contact = (Contact)args.SelectedItem; - - sender.Text = contact.DisplayName; + rootPage.NotifyUser("Suggestion chosen: " + contact.DisplayName, NotifyType.StatusMessage); } /// diff --git a/Samples/XamlAutoSuggestBox/shared/Contacts.txt b/Samples/XamlAutoSuggestBox/shared/Contacts.txt index 1c784cf1..63e7ed50 100644 --- a/Samples/XamlAutoSuggestBox/shared/Contacts.txt +++ b/Samples/XamlAutoSuggestBox/shared/Contacts.txt @@ -526,7 +526,7 @@ Ray Layla Springe Chadds Ford Winery -Joesph +Joseph Degonia A R Packaging Annabelle diff --git a/Samples/XamlAutoSuggestBox/shared/Scenario1.xaml b/Samples/XamlAutoSuggestBox/shared/Scenario1.xaml index 56db59e3..b10661f8 100644 --- a/Samples/XamlAutoSuggestBox/shared/Scenario1.xaml +++ b/Samples/XamlAutoSuggestBox/shared/Scenario1.xaml @@ -34,7 +34,7 @@ In Windows 10, SearchBox is no longer being supported, in favor of AutoSuggestBox. As such, this example is meant to showcase using AutoSuggestBox to get a SearchBox-style experience. The key events in AutoSuggestBox that you will need to utilize are TextChanged, SuggestionChosen, and QuerySubmitted. Using these events in conjunction with QueryIcon will allow you to have the same experience as SearchBox using AutoSuggestBox. • TextChanged - This event is where you will filter your result set based on the text that the user has input. - • SuggestionChosen - This event will allow you to fill in the TextBox with the text of the highlighted item. This is fired as a user keys down the list and when an item is tapped. + • SuggestionChosen - This event is fired as a user keys down the list and when an item is tapped. • QuerySubmitted - This event is where you should take action. There are 2 key properties in the args for this event: ◦ QueryText - This is the text in the TextBox. Use this if ChosenSuggestion is null, as it means that the user either pressed Enter in the TextBox, or clicked on the QueryIcon button. ◦ ChosenSuggestion - If a user tapped on an item in the list, or pressed Enter while it was highlighted, this will contain the data item corresponding to the item in the list that was selected. @@ -50,6 +50,7 @@ x:Name="asb" PlaceholderText="Type a name (e.g. John)" DisplayMemberPath="DisplayName" + TextMemberPath="DisplayName" TextChanged="asb_TextChanged" QueryIcon="Find" QuerySubmitted="asb_QuerySubmitted"