WPF.NET application crashes, ComboBox events, and menus do not fire on tablets with Windows 10 Creators Update, .NET 4.7, or KB4034658

When I click the shaky / nerve / hammer with the pen on the ComboBox, click on the elements, move the pen by clicking ... after 5 or 10 minutes, the control will stop working.
Then I can open the ComboBox, click on the element, the element is highlighted, but nothing happens: the ComboBox does not close and the click event is not fired.
The same thing happens with ContextMenu. And when an error occurs, all ComboBoxes and all menus no longer work. This happens when I press with a pen or finger, the mouse works great even when the controls are no longer suitable for use with a pen or finger.

Under normal use, this happens about 5 times per business day, which is very annoying for my users. You need some kind of "patience" to reproduce the error, you may need more than 10 minutes ... but it will happen.

I made a simple test application with one ComboBox and one button with ContextMenu, you can re-create an error with it.
The target structure of my application is 4.6.1, compiled with VS2015. My application works fine with Windows 8.1 and Windows 10 Anniversary, with .NET 4.6.1 and 4.6.2.

Error on Microsoft Surface Pro 3 and Pro 4 using - Update for Windows 10 developers (including .NET 4.7)
 - Update for Windows 10 and update .NET 4.7
 - Windows 8.1 and .NET 4.7 installed
 - Updated update for Windows 10 (.NET 4.6.2) and KB4034658.

In the first three scenarios, I learned how to block Creators and .NET 4.7 from installing Windows Update for at least the next 6 months.
But with the cumulative update in August 2017 KB4034658, the current settings for my Windows 10 users either live with errors or completely deactivate all Windows updates.

Here is the code for my test application:

MainWindow.xaml

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DotNet47ComboBoxAndMenuError"
        mc:Ignorable="d"
        Title="" Height="900" Width="715" WindowStartupLocation="Manual" WindowState="Maximized">
    <Grid>
        <WrapPanel>
            <ComboBox FontSize="16" Width="150">
                <ComboBoxItem>ComboBoxItem 1</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 2</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 3</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 4</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 5</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 6</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 7</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 8</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 9</ComboBoxItem>
            </ComboBox>
            <Button x:Name="btnMenu" Content="MENU" FontSize="16" Margin="100,0,0,0">
                <Button.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="MenuItem 1"></MenuItem>
                        <MenuItem Header="MenuItem 2"></MenuItem>
                        <MenuItem Header="MenuItem 3"></MenuItem>
                        <MenuItem Header="MenuItem 4"></MenuItem>
                        <MenuItem Header="MenuItem 5"></MenuItem>
                        <MenuItem Header="MenuItem 6"></MenuItem>
                        <MenuItem Header="MenuItem 7"></MenuItem>
                        <MenuItem Header="MenuItem 8"></MenuItem>
                        <MenuItem Header="MenuItem 9"></MenuItem>
                    </ContextMenu>
                </Button.ContextMenu>
            </Button>
        </WrapPanel>
    </Grid>
</Window>

Only XAML, absolutely no code in my test application.

, . , ; , : . , , .

, Windows 10 Creators Update .NET 4.7, , KB4034658. , , , , - .

Windows:

      <Category>0</Category>
      <ComputerName>DESKTOP-XXXXXX</ComputerName>
      <EventCode>1026</EventCode>
      <EventIdentifier>1026</EventIdentifier>
      <EventType>1</EventType>
      <InsertionStrings>Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IndexOutOfRangeException
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Insert(System.__Canon, System.__Canon, Boolean)
   at System.Windows.Input.StylusWisp.WispLogic.CoalesceAndQueueStylusEvent(System.Windows.Input.RawStylusInputReport)
   at System.Windows.Input.PenContext.FirePackets(Int32, Int32[], Int32)
   at System.Windows.Input.PenThreadWorker.FlushCache(Boolean)
   at System.Windows.Input.PenThreadWorker.FireEvent(System.Windows.Input.PenContext, Int32, Int32, Int32, Int32, IntPtr)
   at System.Windows.Input.PenThreadWorker.ThreadProc()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

</InsertionStrings>
      <Logfile>Application</Logfile>
      <Message>Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IndexOutOfRangeException
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Insert(System.__Canon, System.__Canon, Boolean)
   at System.Windows.Input.StylusWisp.WispLogic.CoalesceAndQueueStylusEvent(System.Windows.Input.RawStylusInputReport)
   at System.Windows.Input.PenContext.FirePackets(Int32, Int32[], Int32)
   at System.Windows.Input.PenThreadWorker.FlushCache(Boolean)
   at System.Windows.Input.PenThreadWorker.FireEvent(System.Windows.Input.PenContext, Int32, Int32, Int32, Int32, IntPtr)
   at System.Windows.Input.PenThreadWorker.ThreadProc()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()
</Message>
      <RecordNumber>250</RecordNumber>
      <SourceName>.NET Runtime</SourceName>
      <TimeGenerated>8/1/2017 2:10:56 PM</TimeGenerated>
      <TimeWritten>8/1/2017 2:10:56 PM</TimeWritten>
      <Type>Error</Type>

:

      <Category>0</Category>
      <ComputerName>DESKTOP-XXXXXX</ComputerName>
      <EventCode>1026</EventCode>
      <EventIdentifier>1026</EventIdentifier>
      <EventType>1</EventType>
      <InsertionStrings>Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentNullException
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].FindEntry(System.__Canon)
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TryGetValue(System.__Canon, System.__Canon ByRef)
   at System.Windows.Input.StylusLogic.ProcessInputReport(System.Windows.Input.RawStylusInputReport)
   at System.Windows.Input.PenContext.FirePenOutOfRange(Int32, Int32)
   at System.Windows.Input.PenThreadWorker.ThreadProc()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

</InsertionStrings>
      <Logfile>Application</Logfile>
      <Message>Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentNullException
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].FindEntry(System.__Canon)
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TryGetValue(System.__Canon, System.__Canon ByRef)
   at System.Windows.Input.StylusLogic.ProcessInputReport(System.Windows.Input.RawStylusInputReport)
   at System.Windows.Input.PenContext.FirePenOutOfRange(Int32, Int32)
   at System.Windows.Input.PenThreadWorker.ThreadProc()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()
</Message>
      <RecordNumber>534</RecordNumber>
      <SourceName>.NET Runtime</SourceName>
      <TimeGenerated>7/31/2017 1:13:39 PM</TimeGenerated>
      <TimeWritten>7/31/2017 1:13:39 PM</TimeWritten>
      <Type>Error</Type>

https://connect.microsoft.com/VisualStudio https://github.com/Microsoft/dotnet/issues

, .

, MS Surface. , . ... WPF - .

, Surface , Microsoft, , ​​MS asap. , , MS Surface Tablets , , DPI?

+3
1

, . RealTimeStylus , .

RealTimeStylus ScrollViewer, touch. , .

, (, , ).

    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 device class.
                Type devicesType = devices.GetType();

                // Loop until there are no more devices to remove.
                int count = devices.Count + 1;

                while (devices.Count > 0)
                {
                    // Remove the first tablet device in the devices collection.
                    devicesType.InvokeMember("HandleTabletRemoved", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic, null, devices, new object[] { (uint)0 });

                    count--;

                    if (devices.Count != count)
                    {
                        throw new Win32Exception("Unable to remove real-time stylus support.");
                    }
                }
            }
        }
    }
0

All Articles