Replies: 1 comment 1 reply
-
I think redirecting focus on a I think Word is setting focus explicitly to the text after font type has changed (and also after font size has changed etc). If you want to fiddle around with lost/gotfocus yourself, try this in your public class MyMainWindow
{
static MyMainWindow()
{
// see https://docs.avaloniaui.net/docs/concepts/input/routed-events#class-handlers:
Avalonia.Input.InputElement.GotFocusEvent.AddClassHandler<MyMainWindow>((x, e) => x.OnGotFocus(e));
Avalonia.Input.InputElement.LostFocusEvent.AddClassHandler<MyMainWindow>((x, e) => x.OnLostFocus(e));
}
InputElement _previousFocused;
void OnGotFocus(Avalonia.Input.GotFocusEventArgs args)
{
// remember args.Source (should be of type InputElement)
_previousFocused = args.Source is InputElement x ? x : _previousFocused;
}
void OnLostFocus(Avalonia.Interactivity.RoutedEventArgs args)
{
_previousFocused.Focus(); // but I doubt this will do what you want
}
} But as I said, setting focus explicitly on a change by the user is probably more stable. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
Is there a way to save the previous focused element and bring it back at lost focus of the current one?
Like in Ms Word, you type a text in the document, then you change the focus to the font family combo and you type the name of the font you want. When you validate the combo, the focus is back to the text at the right place.
Beta Was this translation helpful? Give feedback.
All reactions