I'm trying to set focus to an Entry
control when a page loads to automatically trigger the keyboard.
However, while the Entry
control receives focus (caret blinking) if done during Loaded
event, the keyboard doesn't appear.
If done only in the Appearing
event, the caret doesn't even appear.
My page has a single Entry
like:
<StackLayout>
<Entry x:Name="RoundsEntry" Keyboard="Numeric" />
</StackLayout>
In the code-behind, I'm setting focus during the Loaded
event:
public RoundsPage()
{
InitializeComponent();
Loaded += RoundsPage_Loaded;
// For Shell navigation, the Appearing event makes more sense,
// as page is only loaded once, but we want the Entry control
// to receive focus every time the user returns to the page.
Appearing += RoundsPage_Loaded;
}
private void RoundsPage_Loaded(object? sender, EventArgs e)
{
RoundsEntry.Focus();
}
Manually tapping the Entry
control (even though it already has focus) does trigger the keyboard.
Am I missing something, or is there some other option to programmatically trigger (and later hide) the keyboard?
(Tested on Android.)
Edit: seems related to this issue on GitHub, so I think I'm looking for a viable workaround until it's fixed.