当我用ComboBox上的笔点击摇晃/紧张/锤击时,单击项目,移动笔,同时单击... 5或10分钟后控件停止工作。 然后我可以打开ComboBox,可以点击一个项目,项目会突出显示,但没有任何反应:ComboBox没有关闭,也没有点击事件被触发。 ContextMenu也会发生同样的错误。当错误发生时,所有ComboBox和所有菜单都不再起作用。当我用笔或用我的手指点击时,即使控件不再可用于笔或手指,鼠标也能正常工作。
在正常使用情况下,这种情况每个工作日大约发生5次,对我的用户来说非常烦人。您需要一些“耐心”来重现错误,也许需要超过10分钟...但它确实发生了。
我用一个ComboBox和一个带有ContextMenu的按钮制作了一个简单的测试应用程序,你可以用它重新产生错误。 我的应用程序的目标框架是4.6.1,使用VS2015编译。我的应用程序适用于Windows 8.1和Windows 10 Anniversary,使用.NET 4.6.1和4.6.2。
该错误发生在Microsoft Surface Pro 3和Pro 4上 - Windows 10 Creators更新(包括.NET 4.7) - 安装了Windows 10周年更新和.NET 4.7 - 已安装Windows 8.1和.NET 4.7 - 安装了Windows 10周年更新(.NET 4.6.2)和KB4034658!
对于前三个场景,我发现如何阻止Creator Update和.NET 4.7被Windows Update安装,至少在接下来的6个月内。 但是对于2017年8月的累积更新KB4034658,我的Windows 10用户的当前选项要么是要处理错误,要么完全停用所有Windows更新。
这是我的测试应用程序的代码:
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>
只有XAML,我的测试应用中绝对没有代码。
我的用户还报告,偶尔单击按钮在对话框窗口中不执行任何操作。发生这种情况时,他们只能点击右上方的关闭按钮;如上所述,下拉菜单和菜单在主窗口中不再起作用:它们需要关闭并重新启动应用程序。没有用样本再现这个,我想这是同样的错误。
此外,我的应用程序偶尔会崩溃与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 - 太奇特了。
有了这篇文章,我希望一些拥有Surface的人会重新产生错误并向微软报告这个错误,以增加MS尽快修复它的可能性。另外,我想知道这个错误是仅在MS Surface平板电脑上还是在其他平板电脑上发生,可能只在High-DPI平板电脑上?
我们找到了一种解决方法,但它也有一些缺点。当disabling the RealTimeStylus在应用程序启动时,我们不能再重现该问题。
但是,禁用RealTimeStylus
也会使用触摸禁用ScrollViewer swiping。它也可能影响手写笔的使用,我无法测试这一点。
虽然这种解决方案不是最佳解决方案,但对于您的情况(或至少是一个起点)可能就足够了。
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.");
}
}
}
}
}
这个问题有点回来,但我对“不再响应GUI”有一个解释。
如果项目在列表视图中没有100%可见(已存放)并且您执行了单击,则列表视图会首先滚动项目完全可见。一切都适用于鼠标。但TouchUp事件在滚动之前就会触发。这正是错误发生的地方。我通过等待“Click-Event”来绕过这个,无论是触摸还是鼠标,10ms然后才执行我的动作。因此,错误是我固定的。