Fix FocusManager.FocusedElement on canceled/redirected focus by MrJul · Pull Request #21047 · AvaloniaUI/Avalonia (original) (raw)

What does the pull request do?

This PR fixes FocusManager.Focus() to properly set FocusManager.FocusedElement (an internal attached property set on each focus scope) when the focus change has been canceled or redirected using the LosingFocus event.

What is the current behavior?

Focus cancellation or redirection incorrectly updates the focused element in the focus scope to the requested element unconditionally.

What is the updated/expected behavior with this PR?

Focus cancellation or redirection updates the focused element in the focus scope to match the element that is actually focused.
Additionally, FocusManager.Focus() now only returns true if the requested element is the one now focused.

Notes

There's an opportunity to simplify the code between FocusManager and KeyboardDevice in the future.

Fixed issues