tags:

views:

31

answers:

1

I implemented something in Windows Forms similar to DragMove but with boundaries set to 10 units of the margins of the primary screen.

When switching over to WPF I found this thread to be useful in achieving the same result.

However, since this is a post-move event, what happens is that if my window is dragged beyond the boundaries I set, it "jumps" back. I would like to avoid this effect as it looks terrible.

Is there a simple way to avoid the window to be moved outside a given area without using the LocationChanged event? I basically want to restrict the movement of the window before it happens.

+1  A: 

These this are very hard to achieve with WPF because it does not expose the base Win32 functions and events like WinForms did. I had a project where I needed to to resize a window and I had to use PInvoke SetWindowPos to do this in a normal manner.

AddHook may help you, but this will still be quite difficult. See http://www.wpfmentor.com/2009/01/how-to-get-hwnd-and-hook-into-wndproc.html and http://msdn.microsoft.com/en-us/library/system.windows.interop.hwndsource.addhook.aspx for more information.

Pieter
Funny enough, this was easy peasy in WindowsForms... :\
brunodecarvalho