FrameworkElement.PredictFocus(FocusNavigationDirection) 메서드

정의

제공된 포커스 이동 방향에 대해 이 요소를 기준으로 포커스를 받을 다음 요소를 결정하며 실제로 포커스를 이동하지는 않습니다.Determines the next element that would receive focus relative to this element for a provided focus movement direction, but does not actually move the focus.

public:
 override System::Windows::DependencyObject ^ PredictFocus(System::Windows::Input::FocusNavigationDirection direction);
public override sealed System.Windows.DependencyObject PredictFocus (System.Windows.Input.FocusNavigationDirection direction);
override this.PredictFocus : System.Windows.Input.FocusNavigationDirection -> System.Windows.DependencyObject
Public Overrides NotOverridable Function PredictFocus (direction As FocusNavigationDirection) As DependencyObject

매개 변수

direction
FocusNavigationDirection

예상 포커스 변경을 결정할 방향입니다.The direction for which a prospective focus change should be determined.

반환

DependencyObject

포커스를 실제로 이동하면 포커스가 이동할 다음 요소입니다.The next element that focus would move to if focus were actually traversed. 제공된 방향에 대해 이 요소를 기준으로 포커스를 이동할 수 없는 경우 null이 반환될 수 있습니다.May return null if focus cannot be moved relative to this element for the provided direction.

예외

TraversalRequest에서 Next, Previous, First, Last 중 한 방향을 지정합니다.Specified one of the following directions in the TraversalRequest: Next, Previous, First, Last. 이러한 방향은 PredictFocus(FocusNavigationDirection)에 사용할 수 없지만 MoveFocus(TraversalRequest)에는 사용할 수 있습니다.These directions are not legal for PredictFocus(FocusNavigationDirection) (but they are legal for MoveFocus(TraversalRequest)).

예제

다음 예제에서는 가능한 몇 가지 단추 입력을 처리 하는 처리기를 구현 합니다. 각 단추는 가능한를 나타냅니다 FocusNavigationDirection .The following example implements a handler that handles several possible button inputs, each button representing a possible FocusNavigationDirection. 처리기는 현재 키보드 포커스가 있는 요소를 추적 하 고 PredictFocus 해당 요소에 대해를 호출 하며 제공 된 FocusNavigationDirection 형식 매개 변수에 대 한 초기화로 적절 한를 지정 합니다 TraversalRequest .The handler tracks the element with current keyboard focus, and calls PredictFocus on that element, and specifies the appropriate FocusNavigationDirection as initialization for the TraversalRequest type parameter provided. 처리기는 해당 요소로 이동 하는 대신 MoveFocus 시각화를 위해 예측 된 포커스 대상의 물리적 차원을 변경 합니다.Instead of moving to that element as MoveFocus would do, the handler changes the physical dimensions of the predicted focus destination for visualization purposes.

    private void OnPredictFocus(object sender, RoutedEventArgs e)
    {
        DependencyObject predictionElement = null;

        UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;

        if (elementWithFocus != null)
        {
            // Only these four directions are currently supported
            // by PredictFocus, so we need to filter on these only.
            if ((_focusMoveValue == FocusNavigationDirection.Up) ||
                (_focusMoveValue == FocusNavigationDirection.Down) ||
                (_focusMoveValue == FocusNavigationDirection.Left) ||
                (_focusMoveValue == FocusNavigationDirection.Right))
            {

                // Get the element which would receive focus if focus were changed.
                predictionElement = elementWithFocus.PredictFocus(_focusMoveValue);
               
                Control controlElement = predictionElement as Control;

                // If a ContentElement.
                if (controlElement != null)
                {
                    controlElement.Foreground = Brushes.DarkBlue;
                    controlElement.FontSize += 10;
                    controlElement.FontWeight = FontWeights.ExtraBold;

                    // Fields used to reset the UI when the mouse 
                    // button is released.
                    _focusPredicted = true;
                    _predictedControl = controlElement;
                }
            }
        }
    }
Private Sub OnPredictFocus(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim predictionElement As DependencyObject = Nothing

    Dim elementWithFocus As UIElement = TryCast(Keyboard.FocusedElement, UIElement)

    If elementWithFocus IsNot Nothing Then
        ' Only these four directions are currently supported
        ' by PredictFocus, so we need to filter on these only.
        If (_focusMoveValue = FocusNavigationDirection.Up) OrElse (_focusMoveValue = FocusNavigationDirection.Down) OrElse (_focusMoveValue = FocusNavigationDirection.Left) OrElse (_focusMoveValue = FocusNavigationDirection.Right) Then

            ' Get the element which would receive focus if focus were changed.
            predictionElement = elementWithFocus.PredictFocus(_focusMoveValue)

            Dim controlElement As Control = TryCast(predictionElement, Control)

            ' If a ContentElement.
            If controlElement IsNot Nothing Then
                controlElement.Foreground = Brushes.DarkBlue
                controlElement.FontSize += 10
                controlElement.FontWeight = FontWeights.ExtraBold

                ' Fields used to reset the UI when the mouse 
                ' button is released.
                _focusPredicted = True
                _predictedControl = controlElement
            End If
        End If
    End If
End Sub

설명

MoveFocus 는 실제로 포커스를 이동 하는 관련 메서드입니다.MoveFocus is the related method that actually does move focus.

적용 대상

추가 정보