0

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.

Savior
  • 54
  • 9
Ville Salonen
  • 2,654
  • 4
  • 29
  • 34
  • 1
    possible duplicate of [WPF: AutoComplete TextBox, ...again](http://stackoverflow.com/questions/2338690/wpf-autocomplete-textbox-again) – Aron May 21 '14 at 06:03

2 Answers2

1

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" />
aifarfa
  • 3,939
  • 2
  • 23
  • 35
  • Agree that using controls from WPF Toolkit or similar is the way to go. Although other answers are good also, this is my suggestion to anyone who comes to find answers to the same problem. – Ville Salonen May 22 '14 at 05:39
1

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.

slugster
  • 49,403
  • 14
  • 95
  • 145
Wolfgang Ziegler
  • 1,675
  • 11
  • 23