我有一个针对.NET 4.5.2的WPF应用程序(但通常在4.6.1下运行),我已经对几个TextBoxes和DataGridTextColumns启用了拼写检查 . 根据用户选择的语言(我们目前仅支持en),通过样式启用拼写检查 . 应用程序和系统文化都设置为en或en-US . 我没有使用任何自定义词典 .
通过以下样式启用拼写检查:
<Style TargetType="TextBox">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Source={x:Static Properties:Settings.Default}, Path=Culture}"
Value="en" />
<Condition Binding="{Binding Source={x:Static diagnostics:Debugger.IsAttached}}"
Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="SpellCheck.IsEnabled"
Value="True" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
(我们使用内置的ApplicationSettings对象存储最后选择的应用程序文化,并且只保存最通用的父文化 . 如果用户的系统设置为“en-US”,我们将只存储“en”以简化操作 . )
TextBox在用于TreeViewItems的DataTemplate中定义,以防万一 . 用户更可能编辑TextBox而不是DataGrid,因此我怀疑问题与TextBox有关 .
在Windows 8和10上,某些用户在拼写检查程序中遇到崩溃,其中包含以下堆栈跟踪:
System.ObjectDisposedException: Safe handle has been closed
at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
at System.Windows.Documents.WinRTSpellerInterop.ClearDictionaries(Boolean isDisposeOrFinalize)
at System.Windows.Documents.WinRTSpellerInterop.Dispose(Boolean disposing)
at System.Windows.Documents.WinRTSpellerInterop.Finalize()
我搜索了Google,StackOverflow和MSDN,但找不到任何对此问题的引用 . 我不知道我的用户正在做什么来触发这种情况,我自己无法重现它 . 我的日志表明,当发生这种情况时,他们没有编辑启用拼写检查的字段(事实上,他们所做的最后一次编辑至少是异常前一分钟或2分钟) . 有没有人有任何想法?
1 回答
此问题在.NET 4.7中得到解决(请参阅Runtime Changes页面上的"WPF Spellchecker"条目) . 请注意,NET 4.7将不会安装在Windows 10 11月更新或更早版本上 . 但是,大多数Windows 10用户现在应该已经参加了周年纪念更新 .