1

Using the new AutoSuggestBox control in Windows Phone 8.1 (WinRT XAML), I am trying to keep the suggestion box open all the time -- even after the user clicks a suggestion.

I have no problem starting with the suggestion box open by programmatically setting AutoSuggestBox.IsSuggestionListOpen = true;

Then I hook the SuggestionChosen event like this:

private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args) {
    sender.Text = args.SelectedItem.ToString();
    sender.IsSuggestionListOpen = true;
}

But unfortunately the suggestion box still closes after selecting an item, even though I set IsSuggestionListOpen to true.

Any help with getting it to stay open after a selection would be appreciated.

Speednet
  • 1,226
  • 10
  • 12

1 Answers1

1

The solution I found to this is to hook the LayoutUpdated event.

I have the AutoSuggestBox in a PickerFlyout, so I only want the suggestion box open if the PickerFlyout is open (obviously). So I set a Tag property on the button that opens the PickerFlyout to identify if the PickerFlyout is open or closed. Then in the LayoutUpdated event of the AutoSuggestBox I set the IsSuggestionListOpen property to true if the PickerFlyout is open (and false if it's not).

The code:

private void PickerFlyout_Opened(object sender, object e) {
    ActivatePickerFlyoutButton.Tag = "open";
}

private void PickerFlyout_Closed(object sender, object e) {
    ActivatePickerFlyoutButton.Tag = "closed";
}

private void AutoSuggestBox_LayoutUpdated(object sender, object e) {
    AutoSuggestBox.IsSuggestionListOpen = ((ActivatePickerFlyoutButton.Tag as string).Equals("open"));
}

That is the only place I need to set the IsSuggestionListOpen property, since the LayoutUpdated event fires at all the right times.

Speednet
  • 1,226
  • 10
  • 12