views:

171

answers:

1

I have an AutoCompleteBox that needs to wrap the filtered items with some other controls, such as a link to a different search form. I need the AutoCompleteBox's dropdown to show even when the filtered list is empty.

Currently, AutoCompleteBox forces the Popup to close when the item list is filtered to nothing.

How do I keep the dang popup open with an empty item list?

A: 

I ran into this problem not long ago when migrating an inherited AutoCompleteBox from SL2 to SL3, so note these code samples are from a custom control that inherits directly from AutoCompleteBox.

First, I declared a class-level variable to hold the Popup portion of the AutoCompleteBox:

private Popup dropdownPopup = null;

Then, overriding the OnApplyTemplate method, you can grab your Popup from the default AutoCompleteBox template:

this.dropdownPopup = this.GetTemplateChild("Popup") as Popup;

Now, you can handle the KeyDown event of the AutoCompleteBox and display your popup whenever you want.

        protected override void OnKeyDown(System.Windows.Input.KeyEventArgs e)
        {
            base.OnKeyDown(e);
            this.dropdownPopup.IsOpen = true;
        }

Finally, you might run into issues if the Text property of the AutoCompleteBox is empty, I found the Popup still doesn't want to open in that case. I overcame that by simply setting the Text to a space if I still wanted it open.

Steve Danner