private void Popup_Opened(object sender, EventArgs e) { // Set the focus on the content of the ContentPresenter. if (_contentPresenter != null) { _contentPresenter.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)); } }
} // func LoadAsync private void UpdateFocus(bool setLogical) { if (setLogical) // activate the element within the parent focus scope { FocusManager.SetFocusedElement(FocusManager.GetFocusScope(this), this); } // if the element is focused if (controlPresenter != null && IsFocused && !controlPresenter.IsKeyboardFocusWithin) { var moveKeyboard = FocusManager.GetFocusedElement(controlPresenter); if (moveKeyboard == null) { controlPresenter?.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)); } else { Keyboard.Focus(moveKeyboard); } } } // proc UpdateFocus
/// <summary> /// Moves the keyboard focus to the content of the currently selected /// <see cref="DockTabItem"/>. /// </summary> /// <returns> /// <see langword="true"/> if the focus was set to the selected content; otherwise, /// <see langword="false"/>. /// </returns> internal bool FocusSelectedContent() { // IMPORTANT: Calling UpdateLayout() when the window is in the process of being closed, // may cause a FatalExecutionEngineError. Always check the IsVisible flag! if (_contentPresenter == null || !IsVisible) { return(false); } // Make sure content is set. UpdateLayout(); // Try to move focus to content. (Does not always work.) bool focusMoved = false; if (!_contentPresenter.IsKeyboardFocusWithin) { focusMoved = _contentPresenter.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); } return(focusMoved); }
/// <summary> /// Moves the logical focus and keyboard focus to the content of the <see cref="AutoHidePane"/>. /// </summary> /// <returns> /// <see langword="true"/> if logical focus and keyboard focus was moved to the content; /// otherwise <see langword="false"/>. /// </returns> public bool FocusContent() { if (!IsLoaded) { Loaded += DeferredFocusContent; _isFocusDeferred = true; return(false); } bool hasFocusMoved = false; var dockTabPane = _contentPresenter.GetContentContainer <DockTabPane>(); if (dockTabPane != null) { hasFocusMoved = dockTabPane.FocusSelectedContent(); } else if (_contentPresenter != null) { hasFocusMoved = _contentPresenter.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)); } return(hasFocusMoved); }
private void Popup_Opened(object sender, EventArgs e) { _contentPresenter?.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)); }