FrameworkElement.MoveFocus(TraversalRequest) Método

Definição

Move o foco do teclado para longe desse elemento e para outro elemento em uma direção de passagem fornecida.Moves the keyboard focus away from this element and to another element in a provided traversal direction.

public:
 override bool MoveFocus(System::Windows::Input::TraversalRequest ^ request);
public override sealed bool MoveFocus (System.Windows.Input.TraversalRequest request);
override this.MoveFocus : System.Windows.Input.TraversalRequest -> bool
Public Overrides NotOverridable Function MoveFocus (request As TraversalRequest) As Boolean

Parâmetros

request
TraversalRequest

A direção para a qual o foco deve ser movido, como um valor da enumeração.The direction that focus is to be moved, as a value of the enumeration.

Retornos

Retorna true se o foco é movido com êxito; false se o elemento de destino na direção especificada não existe ou não pode ter o foco do teclado.Returns true if focus is moved successfully; false if the target element in direction as specified does not exist or could not be keyboard focused.

Exemplos

O exemplo a seguir implementa um manipulador que manipula várias entradas de botão possíveis.The following example implements a handler that handles several possible button inputs. Cada botão representa um possível FocusNavigationDirection.Each button represents a possible FocusNavigationDirection. O manipulador rastreia o elemento com o foco atual do teclado e chama MoveFocus nesse elemento, especificando o FocusNavigationDirection apropriado como inicialização para o parâmetro de tipo TraversalRequest fornecido.The handler tracks the element with current keyboard focus, and calls MoveFocus on that element, by specifying the appropriate FocusNavigationDirection as initialization for the TraversalRequest type parameter provided.

// Creating a FocusNavigationDirection object and setting it to a
// local field that contains the direction selected.
FocusNavigationDirection focusDirection = _focusMoveValue;

// MoveFocus takes a TraveralReqest as its argument.
TraversalRequest request = new TraversalRequest(focusDirection);

// Gets the element with keyboard focus.
UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;

// Change keyboard focus.
if (elementWithFocus != null)
{
    elementWithFocus.MoveFocus(request);
}
' Creating a FocusNavigationDirection object and setting it to a
' local field that contains the direction selected.
Dim focusDirection As FocusNavigationDirection = _focusMoveValue

' MoveFocus takes a TraveralReqest as its argument.
Dim request As New TraversalRequest(focusDirection)

' Gets the element with keyboard focus.
Dim elementWithFocus As UIElement = TryCast(Keyboard.FocusedElement, UIElement)

' Change keyboard focus.
If elementWithFocus IsNot Nothing Then
    elementWithFocus.MoveFocus(request)
End If

Comentários

Essa implementação substitui UIElement.MoveFocus e lacra o método.This implementation overrides UIElement.MoveFocus and seals the method.

Aplica-se a

Veja também