C# WPF DragMove without Window_LocationChanged()

此生再无相见时 提交于 2019-12-10 10:54:36

问题


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:


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.



来源:https://stackoverflow.com/questions/3967432/c-sharp-wpf-dragmove-without-window-locationchanged

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!