Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why all my WPF applications fail to drag outside of their windows since Windows 10 (1809/1903) such as resizing the window or do drag drop?

Tags:

wpf

windows-10

Someday I found that all my WPF applications failed to drag outside of the windows and I cannot resize any windows with real-time preview.

My question is why this happens and how can I solve this?


You can view the animation image showing below:

Cannot resize outside the window

Visual Studio resizing demo

You can notice that when my cursor is outside the window, the resizing immediately stops and the window keep the size when the cursor first leaving the window there. If the cursor reenters the window area and the window resizing resumes.

Not only all the WPF applications that are written by me, but also the other WPF applications reproduces:

  • Visual Studio 2017/2019
  • Snoop
  • ScreenToGif
  • Etc.

Non-WPF applications behave correctly.

This phenomenon happens several months ago since my system version was Windows 10 (1809) and now my system version is Windows 10 (1903) and this issue stands still. WPF application embedded from .NET Framework 3.5/4.5/4.8 and .NET Core 3.0.


Update1: I just cleaned all my drives and reinstalled my Windows 10 Professional (1903, Customer version) with some core applications, the issue still exists. The core applications are Chrome, PalmInput IME, iTunes.

Update2: I've written a WPF application handle the window messages. I find that the 49757 message will stop receiving when I'm resizing window outside of it. The message behaves normally on my friend's system.

like image 985
walterlv Avatar asked Nov 07 '22 16:11

walterlv


1 Answers

Update:

As pointed out by members of the WPF team the recommended way of disabling stylus and touch support in WPF is by using the Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport setting in App.config like this:

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

Also note that this is not a solution, rather a work around, that might not be a good fit for all scenarios.

Original:

Markus Eisenstöck found a work around for this issue. By disabling the tablet support in WPF you will experience the expected behavior. I have tested and it works on my machine (Windows 10 version 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 });
            }
        }
    }
}
like image 132
Magnus Lindhe Avatar answered Nov 15 '22 07:11

Magnus Lindhe