展开时WPF窗口不跟随鼠标

时间:2019-03-25 13:23:45

标签: c# wpf

在一个新的空白WPF应用程序上,我注意到用鼠标调整窗口大小无法正常工作。

缩小窗口时,它可以正常工作。但是当我展开它时,直到离开按钮,窗口才会跟随鼠标,然后窗口突然跳到新的大小。

如果在扩展时我真正缓慢地移动光标,则窗口会跟随光标;但是比那快一点,而且不再。

您可以在我录制的here视频中看到问题。

我尝试了.NET版本4.7.2、4.7.1和4.6。所有人都有相同的问题。

我尝试查找此内容,但在任何地方都未发现此问题。有谁知道是什么原因造成的,以及如何解决它?

此问题可能以某种方式与我的机器隔离,因此是由框架本身以外的其他原因引起的。因此,另一个相关的问题可能是,是否有人在新的WPF项目上看到了这种行为。

更新:这是在新的空白WPF项目中看到的行为,根本没有代码更改。显然,预期的行为是窗口在扩展时跟随光标,就像在收缩时一样。

更新2:@gore85所述,这可能是Windows 10版本1903的问题。当我发布此问题时(我已经发布),我使用的是1903年内部预览版,更新到1903年后,他会看到同样的事情。

1 个答案:

答案 0 :(得分:0)

现在已解决此问题。

https://support.microsoft.com/en-us/help/4517211/windows-10-update-kb4517211

  

解决了调整Windows Presentation Foundation(WPF)大小的问题   应用;他们可能不响应使用鼠标调整大小   直到释放鼠标按钮为止。

这似乎是由错误的平板电脑输入支持引起的。有人设计了a workaround(不使用更新):

public static void DisableWPFTabletSupport()
        {
            // Get a collection of the tablet devices for this window.    
            TabletDeviceCollection devices = System.Windows.Input.Tablet.TabletDevices;


            if (devices.Count > 0)
            {
                // Get the Type of InputManager.  
                Type inputManagerType = typeof(System.Windows.Input.InputManager);


                // Call the StylusLogic method on the InputManager.Current instance.  
                object stylusLogic = inputManagerType.InvokeMember("StylusLogic",
                            BindingFlags.GetProperty | BindingFlags.Instance | 
                            BindingFlags.NonPublic,
                            null, InputManager.Current, null);


                if (stylusLogic != null)
                {
                    // Get the type of the stylusLogic returned 
                    // from the call to StylusLogic.  
                    Type stylusLogicType = stylusLogic.GetType();


                    // Loop until there are no more devices to remove.  
                    while (devices.Count > 0)
                    {
                        // Remove the first tablet device in the devices collection.  
                        stylusLogicType.InvokeMember("OnTabletRemoved",
                                BindingFlags.InvokeMethod | 
                                BindingFlags.Instance | BindingFlags.NonPublic,
                                null, stylusLogic, new object[] { (uint)0 });
                    }
                }
            }
        }