wpf - 为什么我的所有 WPF 应用程序自 Windows 10 (1809/1903) 以来都无法拖动到它们的窗口之外,例如调整窗口大小或进行拖放?

标签 wpf windows-10

有一天我发现我所有的 WPF 应用程序都无法拖动到窗口之外,而且我无法通过实时预览调整任何窗口的大小。

我的问题是为什么会发生这种情况,我该如何解决?

您可以查看下面显示的动画图像:

Cannot resize outside the window

Visual Studio resizing demo

您可以注意到,当我的光标在窗口外时,调整大小立即停止,并且当光标第一次离开窗口时窗口保持大小。如果光标重新进入窗口区域并且窗口大小调整恢复。

不仅是我写的所有 WPF 应用程序,还有其他 WPF 应用程序复制:

  • Visual Studio 2017/2019
  • 窥探
  • ScreenToGif

  • 非 WPF 应用程序行为正确。

    这种现象发生在几个月前,因为我的系统版本是 Windows 10(1809),现在我的系统版本是 Windows 10(1903),这个问题仍然存在。从 .NET Framework 3.5/4.5/4.8 和 .NET Core 3.0 嵌入的 WPF 应用程序。

    更新 1 :我刚刚清理了所有驱动器并重新安装了带有一些核心应用程序的 Windows 10 Professional(1903,客户版本),问题仍然存在。核心应用程序是Chrome、PalmInput IME、iTunes。

    更新 2 :我写了一个 WPF 应用程序来处理窗口消息。我发现49757当我在窗口之外调整窗口大小时,消息将停止接收。该消息在我 friend 的系统上正常运行。

    最佳答案

    更新:

    As pointed out WPF 团队成员推荐的在 WPF 中禁用触控笔和触摸支持的方法是使用 Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport设置在 App.config像这样:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <runtime>
        <AppContextSwitchOverrides value="Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport=true" />
      </runtime>  
    </configuration>
    

    另请注意,这不是一种解决方案,而是一种变通方法,可能并不适合所有场景。

    原文:

    Markus Eisenstöck找到了一个 work around对于这个问题。通过在 WPF 中禁用平板电脑支持,您将体验到预期的行为。我已经测试过,它可以在我的机器上运行(Windows 10 版本 1903 和 .NET Framework 4.6.2):
    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 });
                }
            }
        }
    }
    

    关于wpf - 为什么我的所有 WPF 应用程序自 Windows 10 (1809/1903) 以来都无法拖动到它们的窗口之外,例如调整窗口大小或进行拖放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56354510/

    相关文章:

    c# - 使用浏览器功能时 WPF 应用程序中的脚本错误

    c# - WPF 中的 Bool 到可见性转换器

    c# - 使 Button IsEnabled 状态取决于两个文本框

    winforms - Windows 10 上的 ClickOnce 部署不会将 Assets 文件夹复制到客户端计算机

    performance - Win10下VirtualBox性能不佳

    c# - 如何在 C# 中使用 WMI 查询从 UWF 获取注册表和文件排除项

    c# - 标记在 XML 命名空间中不存在

    wpf - WPF中的对接/填充

    java - 为什么 Windows 10 上的一个 Java 程序会运行 2 个 Java 平台二进制文件?

    windows - 是否存在某些无法在Windows上运行的MAC地址供应商代码,或者我的代码还有其他问题吗?