20

I have a WPF window with a textbox control. The control has an adorner that is made visible when the textbox has keyboardfocus.

As you can see in the screenshot below, the adorner is limited to the bounds of the window. How can I make it so that the full adorner is displayed?

enter image description here

Adorner template is:

<DataTemplate x:Key="ContextualInfoDataTemplate">
    <Border 
        Background="#E1E1E1" 
        CornerRadius="6"
        Margin="50,36,0,0">
        <Border.Effect>
            <DropShadowEffect/>
        </Border.Effect>
        <Grid Width="200" Margin="4,3,4,4">
            <TextBlock TextWrapping="Wrap" Text="OverridenAutomationId"/>
        </Grid>
    </Border>
</DataTemplate>
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
David Ward
  • 3,739
  • 10
  • 44
  • 66

1 Answers1

7

It's not possible. The AdornerLayer confines to the bounds of an AdornerDecorator (the Window has one if you haven't defined one), so it's just not possible to go outside the bounds of that decorator.

You can get what you want using a Popup (MSDN) which defines a popup window, but definitely not using an adorner. Main difference being that the popup is not part of the window's visual tree, so it won't move or resize along with it.

You could also define your own popup window if you want effects that go over the desktop (like the drop shadow you are showing). That'd be indeed tricky, but doable. With a lot of work, you could make it move and resize along with your window too (thus emulating an "out of window adorner"), but that will definitely not be quick or easy to code (for a normal Popup though, you could just hook on your Window's SizeChanged and LocationChanged events and move accordingly)

Jcl
  • 27,696
  • 5
  • 61
  • 92
  • Thanks for this. I was beginning to suspect this might be the case. In a previous attempt I had tried using the Popup, however what I liked about the adorner layer approach was that it did move with the control/window. – David Ward Dec 08 '15 at 12:36
  • 1
    You could hook the `SizeChanged`/`LocationChanged` events of the window (considering the actual textbox is hopefully not moving!) and move the `Popup` accordingly. That should not be all that hard! :-) – Jcl Dec 08 '15 at 12:39
  • 1
    Have a look at PopupEx in this lib. It solves issues regarding moving/sizing. https://github.com/ControlzEx/ControlzEx – James Willock Dec 08 '15 at 16:25
  • @JamesWillock I'm not doing WPF these days, but that definitely looks useful. I remember doing all kind of hacks to get that working -perfectly- :-) – Jcl Dec 08 '15 at 16:57
  • 2
    For reference I ended up using a Popup as suggested – David Ward Dec 18 '15 at 14:06
  • I landed here after implementing WPF's `Adorner` for drag & drop and realizing that it is not suited for dragging between `Window`s or even `ListView`s due to the issue described above. I also ended up building my own window and tracing the location - and it wasn't that crazy: took me less than reading into and figuring out the supposedly "preferred" MS approach. – mike Dec 31 '19 at 00:10