Reputation: 2230
in one of my WinRT App's Views, I'd like the BottomAppBar
to be displayed when a TextBox
loses focus. I played with the GotFocus
and LostFocus
events with which I can manually change the IsOpen
property of the BottomAppBar
accordingly.
Problem is, when the BottomAppBar
is open, if the user clicks on the TextBox
, the BottomAppBar
is closed (standard AppBar behavior), but the TextBox
is not focused (even though the user clicked right on it). The user needs to focus the TextBox
again to be able to type something again.
If I hook myself up in the Closed
event of the BottomAppBar
to try and programmatically set the focus to the TextBox
, it shortly becomes focused, but loses the focus right away and instead, its ScrollViewer gets focused.
Any idea why the TextBox
loses the focus the second time?
Any idea how I can do what I'm trying to achieve?
Thanks!
Upvotes: 0
Views: 1164
Reputation: 31724
Perhaps your BottomAppBar
gets closed when you tap out of it and on the ScrollViewer
and setting the focus to your TextBox
gets overriden by the focus being set to the ScrollViewer
right after that. If you only ever want focus to be on the TextBox
- you could disable focus from ScrollViewer
. You could also try to set the focus after a delay (either with await Task.Delay(50);
or with await Dispatcher.RunAsync(() => /*set focus)
so it might get set after the ScrollViewer
gets focus or handle GotFocus
on the ScrollViewer
and set the focus back to the TextBox
when you want it to keep the focus. Finally make sure that the TextBox
can get focus at all.
Upvotes: 3