开发者

How do I continue showing a decorated empty result list with AutoCompleteBox?

开发者 https://www.devze.com 2022-12-21 19:33 出处:网络
I have 开发者_如何学Can 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 w

I have 开发者_如何学Can 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消