WPF Moving Adorner outside the AdornerLayer or Window

2.6k Views Asked by At

I have an adorner which is moving along with the mouse cursor. However as soon as the mouse moves outside the window the adorner gets cut off.

Is it possible to expand the adorner layer to the whole screen or create a new adorner layer.

2

There are 2 best solutions below

0
On

You probably could do this, though I'm not sure exactly what you're wanting to do with the adorner layer. My solution will only allow the adorner to follow the mouse as long as the window has the focus. Please share what your end goal is so I can better help you.

My idea would be to create a full screen, borderless window with a transparent background to hold whatever controls you want. The non-transparent part of your window would be inside a grid.

  1. Create a new window. Set its WindowBorderStyle to "None", Width and Height to "Auto", and "WindowState" to "Maximized". (I'm not looking at the IDE at the moment, so the property names may be slightly off.)

  2. Copy the XAML code for the grid (or whatever primary container you're using) in your original window, and paste that in your new window. Make sure you replace the empty grid in your new window with the grid you paste.

This should allow you to have the adorner layer follow the mouse around the entire window.

Again, post your exact goal on here, so I can give an answer better suited to your particular needs.

0
On

maybe he wants to draw the selection area i'm encount the same problem, but you can see the link below, it works. http://www.codeproject.com/Articles/22952/WPF-Diagram-Designer-Part-2
I found you cannot receive the mouse event when the background is transparent.if you give the adorner some background, then everything is ok.

protected override void OnRender(DrawingContext dc) {
    dc.DrawRectangle(bg, null, new Rect(RenderSize));
    dc.DrawRectangle(Brushes.Red, null, new Rect(start, end));
}

the bg brush is just like,

private Brush bg = new SolidColorBrush(Color.FromArgb(0x01, 0, 0, 0));