FrameworkElement.PredictFocus(FocusNavigationDirection) 메서드

정의

제공된 포커스 이동 방향에 대해 이 요소를 기준으로 포커스를 받을 다음 요소를 결정하며 실제로 포커스를 이동하지는 않습니다.

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

예상 포커스 변경을 결정할 방향입니다.

반환

포커스를 실제로 이동하면 포커스가 이동할 다음 요소입니다. 제공된 방향에 대해 이 요소를 기준으로 포커스를 이동할 수 없는 경우 null이 반환될 수 있습니다.

예외

TraversalRequest에서 Next, Previous, First, Last 중 한 방향을 지정합니다. 이러한 방향은 PredictFocus(FocusNavigationDirection)에 사용할 수 없지만 MoveFocus(TraversalRequest)에는 사용할 수 있습니다.

예제

다음 예제에서는 가능한 여러 단추 입력을 처리하는 처리기를 구현합니다. 각 단추는 가능한 FocusNavigationDirection을 나타냅니다. 처리기는 현재 키보드 포커스가 있는 요소를 추적하고 해당 요소를 호출 PredictFocus 하며 제공된 형식 매개 변수에 대한 초기화로 적절한 FocusNavigationDirectionTraversalRequest 지정합니다. 처리기는 해당 요소로 MoveFocus 이동하는 대신 시각화를 위해 예측된 포커스 대상의 물리적 차원을 변경합니다.

    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 는 실제로 포커스를 이동하는 관련 메서드입니다.

적용 대상

추가 정보