0

リボン メニューといくつかのテキスト ボックスをメイン パネルに表示する WPF-C# アプリケーションがあります。それらの1つにフォーカスして左矢印を押すと、次のエラーが発生します。他の矢印を押すとうまくいきます。特定のテキスト ボックス メソッドの previewKeyDoyn でブレークポイントを設定しようとしましたが、実行する前に例外がスローされました。

左矢印を押すと、アプリケーションの他のすべてのテキストボックスが正常に機能します。

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)
4

1 に答える 1

0

.NET リフレクターを使用して、ribbonControlsLibrary.dll アセンブリを逆コンパイルしたところ、コードのこの部分が見つかりました。注意深く見ると、right、up、down、および last が使用されていることがわかります。最後の代わりに残す必要があります。この問題を解決する唯一の方法は、.NET Framework 4.5 を使用するか、OnPreviewKeyDown をオーバーライドして左キーを処理することです (例外はスローされませんが、キャレットは前の文字に移動しません)。

私のコード:

protected override void OnPreviewKeyDown(KeyEventArgs e)
{
    if (e.Key == Key.Left)
    {
        e.Handled = true;
    }
}

リボン コントロール ライブラリ.dll:

protected override void OnPreviewKeyDown(KeyEventArgs e)
{
    if (!e.Handled)
    {
        DependencyObject originalSource;
        DependencyObject obj3;
        if (e.Key == Key.Down)
        {
            originalSource = e.OriginalSource as DependencyObject;
            if (originalSource != null)
            {
                UIElement footerPaneHost = this.FooterPaneHost;
                if (((footerPaneHost != null) && footerPaneHost.IsKeyboardFocusWithin) && TreeHelper.IsVisualAncestorOf(footerPaneHost, originalSource))
                {
                    obj3 = RibbonHelper.PredictFocus(originalSource, FocusNavigationDirection.Down);
                    if (((obj3 == null) || (obj3 == originalSource)) && (this.ItemsPaneMoveFocus(FocusNavigationDirection.First) || this.AuxiliaryPaneMoveFocus(FocusNavigationDirection.First)))
                    {
                        e.Handled = true;
                    }
                }
            }
        }
        else
        {
            UIElement auxiliaryPaneHost;
            if (e.Key == Key.Up)
            {
                UIElement element2 = this._popup.TryGetChild();
                if ((element2 != null) && !element2.IsKeyboardFocusWithin)
                {
                    if (this.FooterPaneMoveFocus(FocusNavigationDirection.Last) || this.AuxiliaryPaneMoveFocus(FocusNavigationDirection.Last))
                    {
                        e.Handled = true;
                    }
                }
                else
                {
                    originalSource = e.OriginalSource as DependencyObject;
                    if (originalSource != null)
                    {
                        auxiliaryPaneHost = this.AuxiliaryPaneHost;
                        if (((auxiliaryPaneHost != null) && auxiliaryPaneHost.IsKeyboardFocusWithin) && TreeHelper.IsVisualAncestorOf(auxiliaryPaneHost, originalSource))
                        {
                            obj3 = RibbonHelper.PredictFocus(originalSource, FocusNavigationDirection.Up);
                            if (((obj3 == null) || (obj3 == originalSource)) && (this.ItemsPaneMoveFocus(FocusNavigationDirection.Last) || this.FooterPaneMoveFocus(FocusNavigationDirection.Last)))
                            {
                                e.Handled = true;
                            }
                        }
                    }
                }
            }
            else if ((e.Key == Key.Left) || (e.Key == Key.Right))
            {
                originalSource = e.OriginalSource as DependencyObject;
                if (originalSource != null)
                {
                    if ((e.Key == Key.Left) == (base.FlowDirection == FlowDirection.LeftToRight))
                    {
                        auxiliaryPaneHost = this.AuxiliaryPaneHost;
                        if (((auxiliaryPaneHost != null) && auxiliaryPaneHost.IsKeyboardFocusWithin) && TreeHelper.IsVisualAncestorOf(auxiliaryPaneHost, originalSource))
                        {
                            obj3 = RibbonHelper.PredictFocus(originalSource, FocusNavigationDirection.Last);
                            if (((obj3 != null) && !TreeHelper.IsVisualAncestorOf(auxiliaryPaneHost, obj3)) && RibbonHelper.Focus(obj3))
                            {
                                e.Handled = true;
                            }
                        }
                    }
                    else if (e.Key == Key.Left)
                    {
                        ScrollViewer subMenuScrollViewer = base.SubMenuScrollViewer;
                        if (((subMenuScrollViewer != null) && subMenuScrollViewer.IsKeyboardFocusWithin) && TreeHelper.IsVisualAncestorOf(subMenuScrollViewer, originalSource))
                        {
                            RibbonMenuItem item = originalSource as RibbonMenuItem;
                            if (item == null)
                            {
                                item = TreeHelper.FindVisualAncestor<RibbonMenuItem>(originalSource);
                            }
                            if ((item != null) && !item.CanOpenSubMenu)
                            {
                                obj3 = item.PredictFocus(FocusNavigationDirection.Right);
                                if ((obj3 != null) && RibbonHelper.Focus(obj3))
                                {
                                    e.Handled = true;
                                }
                            }
                        }
                    }
                }
            }
        }
        base.OnPreviewKeyDown(e);
    }
}

FocusNavigationDirection:

public enum FocusNavigationDirection
{
    // Résumé :
    //     Déplacer le focus sur l'élément pouvant être actif suivant dans l'ordre de
    //     tabulation.Non pris en charge pour System.Windows.UIElement.PredictFocus(System.Windows.Input.FocusNavigationDirection).
    Next = 0,
    //
    // Résumé :
    //     Déplacer le focus sur l'élément pouvant être actif précédent dans l'ordre
    //     de tabulation.Non pris en charge pour System.Windows.UIElement.PredictFocus(System.Windows.Input.FocusNavigationDirection).
    Previous = 1,
    //
    // Résumé :
    //     Déplacer le focus sur le premier élément pouvant être actif dans l'ordre
    //     de tabulation.Non pris en charge pour System.Windows.UIElement.PredictFocus(System.Windows.Input.FocusNavigationDirection).
    First = 2,
    //
    // Résumé :
    //     Déplacer le focus sur le dernier élément pouvant être actif dans l'ordre
    //     de tabulation.Non pris en charge pour System.Windows.UIElement.PredictFocus(System.Windows.Input.FocusNavigationDirection).
    Last = 3,
    //
    // Résumé :
    //     Déplacer le focus sur un autre élément pouvant être actif et situé à gauche
    //     de l'élément ayant actuellement le focus.
    Left = 4,
    //
    // Résumé :
    //     Déplacer le focus sur un autre élément pouvant être actif et situé à droite
    //     de l'élément ayant actuellement le focus.
    Right = 5,
    //
    // Résumé :
    //     Déplacer le focus sur un autre élément pouvant être actif et situé plus haut
    //     par rapport à l'élément ayant actuellement le focus.
    Up = 6,
    //
    // Résumé :
    //     Déplacer le focus sur un autre élément pouvant être actif et situé plus bas
    //     par rapport à l'élément ayant actuellement le focus.
    Down = 7,
}
于 2013-07-26T12:16:45.340 に答える