WPF 工具包:VisualStateGroup 错误?
我遇到了一个奇怪的间歇性错误,该错误似乎与 WPF 工具包中的 VisualStateManager 有关。我正在开发一个使用 Toolkit(2009 年 6 月)的应用程序,但不使用 VisualStateManager。尽管如此,我还是收到了以下错误:
'TextColor' name cannot be found in the name scope of 'System.Windows.Controls.Grid'.
不用说,我并没有尝试更改 Grid 控件上的 TextColor 属性。
该异常并不指向我的源代码中的任何特定行。相反,它指向 VisualStateManager 中的一行——我已复制下面的 IL 转储。我还发布了例外的全文。
还有其他人遇到过这个问题吗?感谢您的帮助。
***************************************
EXCEPTION TEXT
***************************************
System.InvalidOperationException was unhandled
Message="'TextColor' name cannot be found in the name scope of 'System.Windows.Controls.Grid'."
Source="PresentationFramework"
StackTrace:
at System.Windows.Media.Animation.Storyboard.ResolveTargetName(String targetName, INameScope nameScope, DependencyObject element)
at System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock, DependencyObject containingObject, INameScope nameScope, DependencyObject parentObject, String parentObjectName, PropertyPath parentPropertyPath, HandoffBehavior handoffBehavior, HybridDictionary clockMappings, Int64 layer)
at System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock, DependencyObject containingObject, INameScope nameScope, DependencyObject parentObject, String parentObjectName, PropertyPath parentPropertyPath, HandoffBehavior handoffBehavior, HybridDictionary clockMappings, Int64 layer)
at System.Windows.Media.Animation.Storyboard.BeginCommon(DependencyObject containingObject, INameScope nameScope, HandoffBehavior handoffBehavior, Boolean isControllable, Int64 layer)
at System.Windows.Media.Animation.Storyboard.Begin(FrameworkElement containingObject, HandoffBehavior handoffBehavior, Boolean isControllable)
at System.Windows.VisualStateGroup.StartNewThenStopOld(FrameworkElement element, Storyboard[] newStoryboards) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\VSM\VisualStateManager\System\Windows\VisualStateGroup.cs:line 109
at System.Windows.VisualStateManager.GoToStateInternal(Control control, FrameworkElement element, VisualStateGroup group, VisualState state, Boolean useTransitions) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\VSM\VisualStateManager\System\Windows\VisualStateManager.cs:line 234
at System.Windows.VisualStateManager.GoToState(Control control, String stateName, Boolean useTransitions) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\VSM\VisualStateManager\System\Windows\VisualStateManager.cs:line 67
at Microsoft.Windows.Controls.ButtonBaseBehavior.UpdateState(Control control, Boolean useTransitions) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\VSM\VisualStateManager\Microsoft\Windows\Controls\ButtonBaseBehavior.cs:line 77
at Microsoft.Windows.Controls.ControlBehavior.UpdateStateHandler(Object o, EventArgs e) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\VSM\VisualStateManager\Microsoft\Windows\Controls\ControlBehavior.cs:line 54
at MS.Internal.ComponentModel.PropertyChangeTracker.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetValue(DependencyPropertyKey key, Object value)
at System.Windows.DependencyObject.SetValue(DependencyPropertyKey dp, Boolean value)
at System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState)
at System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState)
at System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState)
at System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState)
at System.Windows.ReverseInheritProperty.OnOriginValueChanged(DependencyObject oldOrigin, DependencyObject newOrigin, DeferredElementTreeState& oldTreeState)
at System.Windows.Input.MouseDevice.ChangeMouseOver(IInputElement mouseOver, Int32 timestamp)
at System.Windows.Input.MouseDevice.PreNotifyInput(Object sender, NotifyInputEventArgs e)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, 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, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at ProjectManager.App.Main() in D:\Users\dcveeneman\Documents\Visual Studio 2008\Projects\FsProjectManager\ProjectManager\obj\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
VS 2008 拆解
Address: Microsoft.Windows.Controls.ControlBehavior.UpdateStateHandler(object, System.EventArgs)
Dissassembly: (VS 2008 caret indicates exception thrown at line 70, the NOP)
--- C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\VSM\VisualStateManager\Microsoft\Windows\Controls\ControlBehavior.cs
00000000 push ebp
00000001 mov ebp,esp
00000003 sub esp,10h
00000006 mov dword ptr [ebp-4],ecx
00000009 mov dword ptr [ebp-8],edx
0000000c cmp dword ptr ds:[0BB401C8h],0
00000013 je 0000001A
00000015 call 53D8DC91
0000001a xor edx,edx
0000001c mov dword ptr [ebp-0Ch],edx
0000001f mov edx,dword ptr [ebp-8]
00000022 mov ecx,55BDE49Ch
00000027 call 53B3F332
0000002c mov dword ptr [ebp-0Ch],eax
0000002f cmp dword ptr [ebp-0Ch],0
00000033 jne 00000063
00000035 mov ecx,601D43E0h
0000003a call F1D25114
0000003f mov dword ptr [ebp-10h],eax
00000042 mov edx,0BB40010h
00000047 mov ecx,700001A9h
0000004c call 53C84292
00000051 mov edx,eax
00000053 mov ecx,dword ptr [ebp-10h]
00000056 call 51E0669C
0000005b mov ecx,dword ptr [ebp-10h]
0000005e call 53C843C7
00000063 push 1
00000065 mov edx,dword ptr [ebp-0Ch]
00000068 mov ecx,dword ptr [ebp-4]
0000006b mov eax,dword ptr [ecx]
0000006d call dword ptr [eax+48h]
00000070 nop
00000071 mov esp,ebp
00000073 pop ebp
00000074 ret 4
I am getting an odd intermittent bug that seems to ve related to the VisualStateManager in the WPF Toolkit. I am developing an application that uses the Toolkit (June 2009), but not the VisualStateManager. Nonetheless, I am getting the following error:
'TextColor' name cannot be found in the name scope of 'System.Windows.Controls.Grid'.
Needless to say, I am not trying to change a TextColor property on a Grid control.
The exception doesn't point to any particular line in my source code. Instead, it points to a line in the VisualStateManager--I have copied the IL dump below. I have also posted the full text of the exception.
Has anyone else come across this problem? Thanks for your help.
***************************************
EXCEPTION TEXT
***************************************
System.InvalidOperationException was unhandled
Message="'TextColor' name cannot be found in the name scope of 'System.Windows.Controls.Grid'."
Source="PresentationFramework"
StackTrace:
at System.Windows.Media.Animation.Storyboard.ResolveTargetName(String targetName, INameScope nameScope, DependencyObject element)
at System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock, DependencyObject containingObject, INameScope nameScope, DependencyObject parentObject, String parentObjectName, PropertyPath parentPropertyPath, HandoffBehavior handoffBehavior, HybridDictionary clockMappings, Int64 layer)
at System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock, DependencyObject containingObject, INameScope nameScope, DependencyObject parentObject, String parentObjectName, PropertyPath parentPropertyPath, HandoffBehavior handoffBehavior, HybridDictionary clockMappings, Int64 layer)
at System.Windows.Media.Animation.Storyboard.BeginCommon(DependencyObject containingObject, INameScope nameScope, HandoffBehavior handoffBehavior, Boolean isControllable, Int64 layer)
at System.Windows.Media.Animation.Storyboard.Begin(FrameworkElement containingObject, HandoffBehavior handoffBehavior, Boolean isControllable)
at System.Windows.VisualStateGroup.StartNewThenStopOld(FrameworkElement element, Storyboard[] newStoryboards) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\VSM\VisualStateManager\System\Windows\VisualStateGroup.cs:line 109
at System.Windows.VisualStateManager.GoToStateInternal(Control control, FrameworkElement element, VisualStateGroup group, VisualState state, Boolean useTransitions) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\VSM\VisualStateManager\System\Windows\VisualStateManager.cs:line 234
at System.Windows.VisualStateManager.GoToState(Control control, String stateName, Boolean useTransitions) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\VSM\VisualStateManager\System\Windows\VisualStateManager.cs:line 67
at Microsoft.Windows.Controls.ButtonBaseBehavior.UpdateState(Control control, Boolean useTransitions) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\VSM\VisualStateManager\Microsoft\Windows\Controls\ButtonBaseBehavior.cs:line 77
at Microsoft.Windows.Controls.ControlBehavior.UpdateStateHandler(Object o, EventArgs e) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\VSM\VisualStateManager\Microsoft\Windows\Controls\ControlBehavior.cs:line 54
at MS.Internal.ComponentModel.PropertyChangeTracker.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetValue(DependencyPropertyKey key, Object value)
at System.Windows.DependencyObject.SetValue(DependencyPropertyKey dp, Boolean value)
at System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState)
at System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState)
at System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState)
at System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState)
at System.Windows.ReverseInheritProperty.OnOriginValueChanged(DependencyObject oldOrigin, DependencyObject newOrigin, DeferredElementTreeState& oldTreeState)
at System.Windows.Input.MouseDevice.ChangeMouseOver(IInputElement mouseOver, Int32 timestamp)
at System.Windows.Input.MouseDevice.PreNotifyInput(Object sender, NotifyInputEventArgs e)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, 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, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at ProjectManager.App.Main() in D:\Users\dcveeneman\Documents\Visual Studio 2008\Projects\FsProjectManager\ProjectManager\obj\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
VS 2008 DISSASSEMBLY
Address: Microsoft.Windows.Controls.ControlBehavior.UpdateStateHandler(object, System.EventArgs)
Dissassembly: (VS 2008 caret indicates exception thrown at line 70, the NOP)
--- C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\VSM\VisualStateManager\Microsoft\Windows\Controls\ControlBehavior.cs
00000000 push ebp
00000001 mov ebp,esp
00000003 sub esp,10h
00000006 mov dword ptr [ebp-4],ecx
00000009 mov dword ptr [ebp-8],edx
0000000c cmp dword ptr ds:[0BB401C8h],0
00000013 je 0000001A
00000015 call 53D8DC91
0000001a xor edx,edx
0000001c mov dword ptr [ebp-0Ch],edx
0000001f mov edx,dword ptr [ebp-8]
00000022 mov ecx,55BDE49Ch
00000027 call 53B3F332
0000002c mov dword ptr [ebp-0Ch],eax
0000002f cmp dword ptr [ebp-0Ch],0
00000033 jne 00000063
00000035 mov ecx,601D43E0h
0000003a call F1D25114
0000003f mov dword ptr [ebp-10h],eax
00000042 mov edx,0BB40010h
00000047 mov ecx,700001A9h
0000004c call 53C84292
00000051 mov edx,eax
00000053 mov ecx,dword ptr [ebp-10h]
00000056 call 51E0669C
0000005b mov ecx,dword ptr [ebp-10h]
0000005e call 53C843C7
00000063 push 1
00000065 mov edx,dword ptr [ebp-0Ch]
00000068 mov ecx,dword ptr [ebp-4]
0000006b mov eax,dword ptr [ecx]
0000006d call dword ptr [eax+48h]
00000070 nop
00000071 mov esp,ebp
00000073 pop ebp
00000074 ret 4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我简直不敢相信。我发布这个问题后立即找到了答案。发生的事情是这样的:我为 WPF 工具包日历控件创建了一个控件模板(我需要一个没有导航按钮的日历)。因此,我修改了现有控件模板的副本,果然,控件模板确实尝试在布局网格控件上设置(不存在的)TextProperty。它确实发生在原始控件模板使用的 VisualStateGroup 内。
所以,现在我要做的就是弄清楚这个错误是我在修改控件模板时引入的,还是在我开始摆弄它之前就已经存在了。无论如何,谜团已经解开!
大卫·维尼曼
前瞻系统
I can't believe it. I found my answer right after I posted this question. Here's what happened: I created a control template for the WPF toolkit calendar control (I needed a calendar without navigation buttons). So, I modified a copy of the existing control template and sure enough, the control template does try to set a (non-existent) TextProperty on a layout Grid control. And it does occur inside a VisualStateGroup used by the original control template.
So, now all I have to do is figure out whether I introduced the bug when I modified the control template, or whether it was there before I started fiddling with it. In any event, mystery solved!
David Veeneman
Foresight Systems