Ville Salonen
Ville Salonen

Reputation: 2654

Autocompleting TextBox in WPF

I'm trying to implement a UserControl which would act as an autocompleting TextBox. What would be the best way to show a ListBox of available choices below the TextBox? It is imperative that the ListBox does not reserve space for itself: it should be positioned over other controls. Is it possible to place something contained within the UserControl outside the UserControl's frame?

I have tried Popup but one problem with that is that popup doesn't move with the parent so if the parent window is moved, popup is left where it first appeared. There are ways to circumvent to in code behind but if there were a simpler solution, that would obviously be better.

Upvotes: 0

Views: 652

Answers (2)

Wolfgang Ziegler
Wolfgang Ziegler

Reputation: 1685

If you want to do it from scratch you should place the ListBox on the AdornerLayer. The AdornerLayer is an invisible layer (like a glass pane) on top of your Window. This way you can place aribrary UI elements on it without messing up your existing GUI layout.

Upvotes: 1

aifarfa
aifarfa

Reputation: 3939

there are lots of custom AutoCompleteBox including WPF Toolkit but if you really need to implement a new one from scratch.

You can use a static Canvas method for canvas/rectangular element.

Canvas.SetZIndex(object, (int)99);

or XAML style setter solution

<Setter Property="Panel.ZIndex" Value="99" />

Upvotes: 1

Related Questions