C# WPF DragMove 不带 Window_LocationChanged()
我在 Windows 窗体中实现了类似于 DragMove 的功能,但边界设置为主屏幕边距的 10 个单位。
当切换到 WPF 时,我发现此线程对于实现相同的结果很有用。
但是,由于这是一个移动后事件,因此如果我的窗口被拖动到我设置的边界之外,它就会“跳”回来。我想避免这种效果,因为它看起来很糟糕。
有没有一种简单的方法可以避免窗口在不使用 LocationChanged
事件的情况下移动到给定区域之外?我基本上想在发生之前限制窗口的移动。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些使用 WPF 很难实现,因为它不像 WinForms 那样公开基本的 Win32 函数和事件。我有一个项目需要调整窗口大小,并且必须使用 PInvoke SetWindowPos 以正常方式执行此操作。
AddHook 可能会帮助你,但这仍然会很困难。请参阅 http://www. wpfmentor.com/2009/01/how-to-get-hwnd-and-hook-into-wndproc.html 和 http://msdn.microsoft.com/en-us/library/system.windows.interop.hwndsource.addhook.aspx了解更多信息。
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.