Setting the Focus to an Entry in Xamarin.Forms

后端 未结 6 878
天命终不由人
天命终不由人 2020-12-20 13:58

This is just a simplified example, but I\'m trying to set this up so that when I open up this page in my Application, the first thing that happens is the keyboard pops up re

6条回答
  •  清歌不尽
    2020-12-20 14:10

    Can anyone explain to me why this doesn't work

        protected override void OnAppearing()
        {
           base.OnAppearing();
           CustomerNameEntry.Focus();       
        }
    

    But this does (adding async and Task.Delay(1))

        protected override async void OnAppearing()
        {
             base.OnAppearing();
             await Task.Delay(1);
             CustomerNameEntry.Focus();       
        }
    

    I'd rather not add this clutter, it seems hacky but it's the only way I've been able to get it to work (I've also tried invoking on main thread, to no avail).

提交回复
热议问题