0
我有一個帶有菜單和幾個文本框的WPF-C#應用程序到主面板。當我將其中一個焦點並按下左箭頭時,出現以下錯誤。當我按任何其他箭頭它效果很好。我試圖在特定文本框方法的previewKeyDoyn上斷點,但在我可以碰到它之前拋出異常。c#InvalidEnumArgumentException:參數'direction'(3)的值對Enum類型'FocusNavigationDirection'無效
當我按下左箭頭時,我的應用程序中的所有其他文本框都能正常工作。
System.ComponentModel.InvalidEnumArgumentException: La valeur de l'argument 'direction' (3) n'est pas valide pour le type Enum 'FocusNavigationDirection'.
Nom du paramètre : direction
à System.Windows.Input.KeyboardNavigation.IsInDirection(Rect fromRect, Rect toRect, FocusNavigationDirection direction)
à System.Windows.Input.KeyboardNavigation.FindNextInDirection(DependencyObject sourceElement, Rect sourceRect, DependencyObject container, FocusNavigationDirection direction, Double startRange, Double endRange)
à System.Windows.Input.KeyboardNavigation.MoveNext(DependencyObject sourceElement, DependencyObject container, FocusNavigationDirection direction, Double startRange, Double endRange)
à System.Windows.Input.KeyboardNavigation.GetNextInDirection(DependencyObject sourceElement, FocusNavigationDirection direction)
à System.Windows.Input.KeyboardNavigation.PredictFocusedElement(DependencyObject sourceElement, FocusNavigationDirection direction)
à System.Windows.FrameworkElement.PredictFocus(FocusNavigationDirection direction)
à Microsoft.Windows.Controls.Ribbon.RibbonHelper.PredictFocus(DependencyObject element, FocusNavigationDirection direction) dans e:\dd\WPFOOB\src\wpfoob\Ribbon\RibbonControlsLibrary\Microsoft\Windows\Controls\Ribbon\RibbonHelper.cs:ligne 488
à Microsoft.Windows.Controls.Ribbon.RibbonApplicationMenu.OnPreviewKeyDown(KeyEventArgs e) dans e:\dd\WPFOOB\src\wpfoob\Ribbon\RibbonControlsLibrary\Microsoft\Windows\Controls\Ribbon\RibbonApplicationMenu.cs:ligne 520
à System.Windows.UIElement.OnPreviewKeyDownThunk(Object sender, KeyEventArgs e)
à System.Windows.Input.KeyEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
à System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
à System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
à System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
à System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
à System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
à System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
à System.Windows.Input.InputManager.ProcessStagingArea()
à System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
à System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
à System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
à System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
à System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
à System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
à System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
à MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
不知道這是否幫助,但 「最後」 是3.它記錄爲:\t最後\t按焦點順序將焦點移至最後一個可聚焦元素。不支持PredictFocus。所以,'Last'不應該被傳遞給堆棧中的'System.Windows.FrameworkElement.PredictFocus'。 (我注意到前一幀有調試信息:'àMicrosoft.Windows.Controls.Ribbon.RibbonHelper.PredictFocus(DependencyObject element,FocusNavigationDirection direction)dans e:\ dd \ WPFOOB \ src \ wpfoob \ Ribbon \ RibbonControlsLibrary \ Microsoft \ Windows \ Controls \ Ribbon \ RibbonHelper.cs:ligne 488')也許你可以在那裏斷點? – 2013-07-25 14:01:46
失敗了,您是否嘗試過在Ribbon類中使用'RibbonApplicationMenu.OnPreviewKeyDown()'?這應該讓你在引發異常之前潛入(而事件處理程序可能不夠早)。 – 2013-07-25 14:09:24
我從官方微軟網站下載了RibbonControlsLibrary.dll:http://www.microsoft.com/en-us/download/confirmation.aspx?id=11877。我不能斷點在VS 2010這個DLL。我有這個DLL的最新版本(4.0.0.11019)。這個DLL有錯誤嗎? – Heyjee