当用户移动窗口时,PushFrame会锁定WPF窗口

Joe*_*tti 12 .net c# wpf

我正在使用PushFrame来确保我的窗口在执行其他代码之前完成绘图.我的应用程序有一些时间敏感的功能,需要在我继续执行代码之前更新窗口.

所以我使用msdn的样本:http://msdn.microsoft.com/en-us/library/vstudio/system.windows.threading.dispatcher.pushframe (v=vs.110) .aspx

哪个工作得很好,除非,如果用户在此代码执行窗口时拖动我的窗口并且您只能使用ctrl-alt-del返回它.

有任何想法吗?

fvo*_*dic 5

应用程序似乎已冻结,因为从用户代码调用DragMove()后,窗口调整大小或操作不会自动释放鼠标捕获Dispatcher.PushFrame().

解决方法是在调用之前从捕获鼠标的应用程序中的任何窗口手动释放鼠标捕获Dispatcher.PushFrame():

        ...
        if (priority < DispatcherPriority.Loaded)
        {
            IntPtr capturingHandle = GetCapture();
            for (int i = 0; i < Application.Current.Windows.Count; i++)
            {
                if (new WindowInteropHelper(
                                            Application.Current.Windows[i]
                                           ).Handle == capturingHandle)
                {
                    Mouse.Capture(
                                  Application.Current.Windows[i],
                                  CaptureMode.Element
                                 );
                    Application.Current.Windows[i].ReleaseMouseCapture();
                    break;
                }
            }
        }
        ...
Run Code Online (Sandbox Code Playgroud)

此解决方法使用GetCapture()p/invoke声明:

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr GetCapture();
Run Code Online (Sandbox Code Playgroud)


Hrv*_*eša 3

不幸的是,我没有适合您的解决方案,但只能确认我们也可以在我们的应用程序(以及 50 行示例程序)中重现此问题。请随意为此连接问题投票。