简体   繁体   中英

AppBar button-Click event is raised before the LostFocus event of the TextBox in UWP

I have a Textbox tha has LostFocus event, one button that has Click event, and one appbarButton with click event. Whenever I click on the non-appbar button, if the focus was in the text box it always calls the Lostfocus event before click event. But. when I do same thing by clicking an appbar button, it never allows Lostfocus to run before its click event. I tried making LostFocus as async method but nothing is working the way I want. Can anyone help me with the solution?

Clicking on the AppBarButton without affecting the focus of other controls is a design.

If you want to do some processing in TextBox.LostFocus , you can do this:

private void AppBarButton_Click(object sender, RoutedEventArgs e)
{
    (sender as AppBarButton).Focus(FocusState.Pointer);
    // do other things...
}

After manually setting the focus to the AppBarButton , the TextBox will lose focus, and your task will continue normally.

Set AllowFocusOnInteraction = true of the AppBar button. This will trigger the LostFocus event first if any field losses focus before the Click of the AppBar button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM