FrameworkElement.PredictFocus(FocusNavigationDirection) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
제공된 포커스 이동 방향에 대해 이 요소를 기준으로 포커스를 받을 다음 요소를 결정하지만 실제로 포커스를 이동하지는 않습니다.
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 될 수 있습니다.
예외
에서 다음 방향 중 하나를 지정했습니다.TraversalRequestNextPreviousFirstLast 이러한 지침에 대 한 PredictFocus(FocusNavigationDirection) 법적 되지 않습니다 (하지만 그들은에 대 한 MoveFocus(TraversalRequest)법적).
예제
다음 예제에서는 가능한 여러 단추 입력을 처리하는 처리기를 구현합니다. 각 단추는 가능한 FocusNavigationDirection단추를 나타냅니다. 처리기는 현재 키보드 포커스가 있는 요소를 추적하고 해당 요소를 호출 PredictFocus 하며 제공된 형식 매개 변수에 대한 FocusNavigationDirection 초기화로 적절한 TraversalRequest 요소를 지정합니다. 처리기는 해당 요소로 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 는 실제로 포커스를 이동하는 관련 메서드입니다.