wpfui icon indicating copy to clipboard operation
wpfui copied to clipboard

AutoSuggestBox stays showing all suggestions even there is no text in the field

Open yukina3230 opened this issue 2 years ago • 1 comments

Normally if I type in some text and the SuggestBox still works fine.

Screenshot 2022-08-23 155234

But when I clear all the text, the box will shows all suggestions, it cannot be unfocus by clicking on other controls, and sometimes it shows on top of other windows. This bug happened on the Demo App as well.

Screenshot 2022-08-23 155309

image

yukina3230 avatar Aug 23 '22 09:08 yukina3230

I've got the same issue. The moment the textbox is empty, the suggestions pop up and won't go away no matter what, including being shown on top of other windows when your app isn't even in focus.

image

As a work-around I tried clearing the suggestions when the box is empty and re-adding when not, but the suggestion box still keeps showing, it's just empty..

Then I tried binding IsSuggestionListOpen so I could set it to false when the text is changed, but it turns out, it's already false and the suggestions show even when IsSuggestionListOpen is false.. The getter of IsSuggestionListOpen is also never ever called.

MulleDK19 avatar Aug 29 '22 23:08 MulleDK19

The solution I found is this:

    protected override void OnLostFocus(RoutedEventArgs e)
    {
        IsSuggestionListOpen = false;
        base.OnLostFocus(e);
    }

Setting the binding property to false on lost focus since its a textbox. In my case I created a subclass as workaround and overrided the method. It could be easily implemented in the actual control.

giuseppetrematerra avatar Sep 24 '22 16:09 giuseppetrematerra

In order to close the popup even if apps are switched, I also made this:

    protected override void OnInitialized(EventArgs e)
    {
        base.OnInitialized(e);
        Window parentWindow = Window.GetWindow(this);
        parentWindow.Deactivated += ParentWindow_Deactivated;
    }

    private void ParentWindow_Deactivated(object? sender, EventArgs e)
    {
        IsSuggestionListOpen = false;
    }

So on window deactivated, it closes the popup

giuseppetrematerra avatar Sep 25 '22 10:09 giuseppetrematerra