Skip to content

Commit

Permalink
Windows 10 Version 1607 - September 2017 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnewthing committed Sep 14, 2017
2 parents 3809239 + b421089 commit 50c35a5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
16 changes: 11 additions & 5 deletions Samples/XamlAutoSuggestBox/cpp/Scenario1.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ void Scenario1::asb_TextChanged(AutoSuggestBox^ sender, AutoSuggestBoxTextChange

sender->ItemsSource = ref new Vector<Contact^>(matchingContacts);
}

if (args->Reason != AutoSuggestionBoxTextChangeReason::SuggestionChosen)
{
rootPage->NotifyUser("", NotifyType::StatusMessage);
}
}

/// <summary>
Expand All @@ -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.</param>
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
Expand All @@ -71,17 +78,16 @@ void Scenario1::asb_QuerySubmitted(AutoSuggestBox^ sender, AutoSuggestBoxQuerySu
}

/// <summary>
/// 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.
/// </summary>
/// <param name="sender">The AutoSuggestBox that fired the event.</param>
/// <param name="args">The args contain SelectedItem, which contains the data item of the item that is currently highlighted.</param>
void Scenario1::asb_SuggestionChosen(AutoSuggestBox^ sender, AutoSuggestBoxSuggestionChosenEventArgs^ args)
{
auto contact = safe_cast<Contact^>(args->SelectedItem);

sender->Text = contact->DisplayName;
rootPage->NotifyUser("Suggestion chosen: " + contact->DisplayName, NotifyType::StatusMessage);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Samples/XamlAutoSuggestBox/cpp/Scenario1.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 11 additions & 5 deletions Samples/XamlAutoSuggestBox/cs/Scenario1.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ private void asb_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEve

sender.ItemsSource = matchingContacts.ToList();
}

if (args.Reason != AutoSuggestionBoxTextChangeReason.SuggestionChosen)
{
rootPage.NotifyUser("", NotifyType.StatusMessage);
}
}

/// <summary>
Expand All @@ -66,6 +71,8 @@ private void asb_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEve
/// and also ChosenSuggestion, which is only non-null when a user selects an item in the list.</param>
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
Expand All @@ -82,17 +89,16 @@ private void asb_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmit
}

/// <summary>
/// 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.
/// </summary>
/// <param name="sender">The AutoSuggestBox that fired the event.</param>
/// <param name="args">The args contain SelectedItem, which contains the data item of the item that is currently highlighted.</param>
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);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Samples/XamlAutoSuggestBox/shared/Contacts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ Ray
Layla
Springe
Chadds Ford Winery
Joesph
Joseph
Degonia
A R Packaging
Annabelle
Expand Down
3 changes: 2 additions & 1 deletion Samples/XamlAutoSuggestBox/shared/Scenario1.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<Paragraph>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.</Paragraph>
<Paragraph>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.</Paragraph>
<Paragraph TextIndent="15">• TextChanged - This event is where you will filter your result set based on the text that the user has input.</Paragraph>
<Paragraph TextIndent="15">• 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.</Paragraph>
<Paragraph TextIndent="15">• SuggestionChosen - This event is fired as a user keys down the list and when an item is tapped.</Paragraph>
<Paragraph TextIndent="15">• QuerySubmitted - This event is where you should take action. There are 2 key properties in the args for this event:</Paragraph>
<Paragraph TextIndent="30">◦ 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.</Paragraph>
<Paragraph TextIndent="30">◦ 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.</Paragraph>
Expand All @@ -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"
Expand Down

0 comments on commit 50c35a5

Please sign in to comment.