本文介绍了C#WPF - DragMove和点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个控制调用DragMove()的一个窗口,在MouseLeftButton下来,但还是点击时发挥作用。

I need a control to call DragMove() for a Window on MouseLeftButton down, but still function when clicked.

如果DragMove()被调用,点击并的MouseLeftButtonUp没有以往任何时候都解雇了,因为DragMove()是一个阻塞调用,直到松开鼠标按钮。

If DragMove() is called, Click and MouseLeftButtonUp are not ever fired because DragMove() is a blocking call until they release the mouse button.

有谁知道一个解决办法,使这项工作?

Does anyone know a workaround to make this work?

我曾尝试基于Thread.sleep代码这个技巧,它允许一个点击工作,如果是超过100毫秒更快,但它并不可靠,为用户的工作:

I have tried this hack based on Thread.Sleep which allows a click to work if it's quicker than 100 milliseconds, but it does not work reliably for users:

                ThreadPool.QueueUserWorkItem(_ =>
                    {
                        Thread.Sleep(100);

                        Dispatcher.BeginInvoke((Action)
                            delegate
                            {
                                if (Mouse.LeftButton == MouseButtonState.Pressed)
                                {
                                    window.DragMove();
                                }
                            });
                    });

编辑:嗯,这破解工作......

Well this hack worked...

                window.DragMove();
                RaiseEvent(new MouseButtonEventArgs(e.MouseDevice, e.Timestamp, MouseButton.Left) 
                    { 
                        RoutedEvent = MouseLeftButtonUpEvent 
                    });

任何人有一个更好的?

Anyone have a better one?

推荐答案

我相信我上面的编辑是最好的解决方案。

I believe my edit above is the best solution.

这篇关于C#WPF - DragMove和点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 17:06