我们使用WPF Tookit DataGrid和.NET 4.0大约1。5年。有些时候我们有例外 - “在某些客户端PC上递归调用Automation Peer API无效”,其他用户没有这个问题。
我们使用了带有Temlate Column的WPF Tookit DataGrid,其中单元格模板有一个复选框(WPF Tookit DataGrid作为CheckBox内容控件)。我们也使用了这个网格中的上下文菜单。
Type : System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Recursive call to Automation Peer API is not valid.
Source : PresentationCore
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : System.Collections.Generic.List`1[System.Windows.Automation.Peers.AutomationPeer] GetChildren()
HResult : -2146233079
Stack Trace : at System.Windows.Automation.Peers.AutomationPeer.GetChildren()
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.ValidateConnected(AutomationPeer connectedPeer)
at MS.Internal.Automation.ElementProxy.StaticWrap(AutomationPeer peer, AutomationPeer referencePeer)
at System.Windows.Automation.Peers.AutomationPeer.UpdateChildrenInternal(Int32 invalidateLimit)
at System.Windows.Automation.Peers.AutomationPeer.UpdateChildren()
at System.Windows.Automation.Peers.AutomationPeer.ResetChildrenCache()
at Microsoft.Windows.Automation.Peers.DataGridItemAutomationPeer.GetChildrenCore()
at System.Windows.Automation.Peers.AutomationPeer.EnsureChildren()
at System.Windows.Automation.Peers.AutomationPeer.GetChildren()
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
at System.Windows.Automation.Peers.AutomationPeer.ValidateConnected(AutomationPeer connectedPeer)
at System.Windows.Automation.Peers.AutomationPeer.AutomationPeerFromInputElement(IInputElement focusedElement)
at System.Windows.Automation.Peers.AutomationPeer.RaiseFocusChangedEventHelper(IInputElement newFocus)
at System.Windows.Input.KeyboardDevice.ChangeFocus(DependencyObject focus, Int32 timestamp)
at System.Windows.Input.KeyboardDevice.TryChangeFocus(DependencyObject newFocus, IKeyboardInputProvider keyboardInputProvider, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
at System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
at System.Windows.Input.KeyboardDevice.Focus(IInputElement element)
at System.Windows.Interop.HwndKeyboardInputProvider.OnSetFocus(IntPtr hwnd)
at System.Windows.Interop.HwndKeyboardInputProvider.FilterMessage(IntPtr hwnd, WindowMessage message, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
请让我们知道相同的解决方案或建议我们做错了什么。
提前致谢
答案 0 :(得分:2)
I have solved this problem using the lower version of WPFToolkit. Earlier I am using the WPFToolkit v3.5.50211.1 which was causing the problem. Now I am using the lower version v3.5.40619.1 to solve the issue.
In WPFToolkit v3.5.50211.1 one bug is fixed related to UI Automation and I guess because of that this automation peer issue is coming while using the latest WPFtoolkit.
check related links-
答案 1 :(得分:0)
在on stackoverflow之前已经问过这个问题,但它从未得到解决。
当我查看代码时,看起来它是由可能正在修改集合的东西引起的,因为正在枚举集合强制在原始枚举已经发生时不可能进行新的枚举。这是由于Automation Peer代码中的框架级保护。
试图找出它发生的方式和原因可能非常棘手,除非你已经包含了在修改集合时记录的代码并设法成功调试它。一种解决方案可能是确保所有集合修改仅在GUI线程上发生,但如果您有大量数据,则可能导致UI阻塞。
但是,这只是猜测。就个人而言,我从未在任何代码中使用过,如果你有成功的代码可以成功重现这一点,我很乐意尝试一下。
我忘了提到有些人建议可能的修复是通过添加:
来覆盖模板protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
{
// Create your own AutomationPeer
// return new MyAutomationPeer(this);
// or return null if you don't need it
return null;
}
这是多么有效,以及它是否删除了任何功能,因为它基本上说你没有同伴,我不知道。