wpf - 透明主窗口和 DragMove 问题“只能在按下鼠标主按钮时调用 DragMove。”

发布于 2024-09-26 13:28:04 字数 865 浏览 0 评论 0原文

我有一个使用透明窗口的 wpf 项目,我为我的对话框窗口和我的 mainwindow 共享这个透明窗口样式。

在关闭使用相同窗口样式的对话框窗口后,我的 MainWindowDragMove() 事件出现错误。更奇怪的是,只有当我处理 MainWindow 上的 Status Bar 中的标签上的 mouseleftbutton 事件时,才会发生此异常。如果我将标签换成按钮并用 click 事件替换 mouseleftbuttondown ,我就不会收到错误。

奇怪的是,弹出的对话框窗口没有实现dragmove,而且我也没有在我的mainwindow周围拖动。不知何故,在调用 showdialog() 后,我的代码执行返回到 mainwindow 后,dragmove 被调用。

目前对我来说一个简单的解决方法是将标签替换为按钮并连接单击事件。

然而,我更感兴趣的是了解导致此问题的原因以及为什么单击事件有效但鼠标事件惨败。

我的“StatusBar”只是一个带有标签和其他堆栈面板(其中包含更多标签)的堆栈面板。

以前有其他人解决过这个问题吗?我是否需要实现某种 mouseclick 事件处理程序重写,以便捕获并取消此异常的发生?

如果需要,可以提供重现代码。我在这里的 dragmove 上获得了足够的点击率,所以我希望这对于其他人来说是一个简单的操作。

预先感谢您的任何帮助!

I have a wpf project which uses transparent windows and I share this transparent window styling for my dialog windows and my mainwindow.

I am getting an error on my DragMove() event of my MainWindow AFTER I close a dialog window that uses the same window style. To make this even more strange this exception only occurs when I handle a mouseleftbutton event on a label in my Status Bar on the MainWindow. IF I swap out the label for a button and replace the mouseleftbuttondown with a click event I do not get the error.

The strange thing is that the dialog window that pops up does not implement dragmove, and I'm not dragging around my mainwindow either. Somehow dragmove gets called after my code execution returns to the mainwindow after a showdialog() call.

An easy fix for me currently is to swap my label for a button and wire up the click event instead.

However, I'm more interested in hearing about what causes this issue and why a click event works but the mouse one fails miserably.

My "StatusBar" is simply a stackpanel with labels and other stackpanels (which contain more labels).

Has anyone else fought this issue before? Would I need to implement some sort of mouseclick event handler override so that I can capture and cancel this exception from happening?

Repro code can be provided if needed. I got enough hits on dragmove here so I am hoping this is an easy one for somebody out there.

Thanks in advance for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我是有多爱你 2024-10-03 13:28:04

我的大脑今天不太正常工作。我忘记了在这种情况下事件的路由。我只需要在按下鼠标按钮时触发的路由事件上设置 Handled 属性。不知何故,我在发布线程之前在调试器中错过了这一点。

my brain isn't working properly today. I forgot about routing of events in this scenario. I simply needed to set the Handled property on my routedevent that fired off when the mousebutton was down. Somehow I missed that in the debugger before posting the thread.

琉璃梦幻 2024-10-03 13:28:04

使无边框窗口可移动的“正确”方法 --> https://stackoverflow.com/a/3275712/146032

确保仅在由事件 MouseLeftButtonDown 触发时调用 DragMove,并且不要调用不要忘记使用 e.Handled=true 来处理事件;

The 'correct' way to make a borderless window movable --> https://stackoverflow.com/a/3275712/146032

Be sure to only call DragMove when triggered by event MouseLeftButtonDown and don't forget to handle the event using e.Handled=true;

清浅ˋ旧时光 2024-10-03 13:28:04

如果您在消息框显示完成时收到此异常。放置 Dragmove();
在 try 内部并在 catch 中清空。

if you receive this exception when messagebox show complete. place Dragemove();
inside try and empty in catch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文