将焦点设置为Xamarin.Forms中的条目 [英] Setting the Focus to an Entry in Xamarin.Forms
问题描述
var namelabel =新标签{Text =你叫什么名字? };
var nameentry = new Entry {Placeholder =Type here ...};
var colorlabel =新标签{text =你喜欢什么颜色? };
var colorentry = new Entry {Placeholder =Type here ...};
Content = new StackLayout {
Spacing = 15,
Children = {namelabel,nameentry,colorlabel,colorentry}
};
如何将页面焦点设置为第一项?另外,在用户输入第一个条目之后,我怎样才能设置这个,以便用户可以按下键盘上的下一步按钮(或者沿着这些线条),应用程序会把它们填入第二条目?
焦点
方法 nameentry.Focus();
如果您希望在出现页面时设置焦点,则应该在 OnAppearing
method
protected override void OnAppearing()
{
base.OnAppearing();
nameentry.Focus();
}
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 ready for the user to type in their response to an Entry field.
var namelabel = new Label { Text = "What is your name?" };
var nameentry = new Entry { Placeholder = "Type here..." };
var colorlabel = new Label { Text = "What's your fav color?" };
var colorentry = new Entry { Placeholder = "Type here..." };
Content = new StackLayout {
Spacing = 15,
Children = { namelabel, nameentry, colorlabel, colorentry }
};
How can I set the focus of the page to the first entry? And additionally, after the user has put in their first entry, how could I set this up so that the user could press a "Next" Button on the Keyboard (or something along those lines) and the app will take them to fill in the second entry?
Use the Focus
method
nameentry.Focus();
If you want the focus to be set when your page appears, you should probably do this in the OnAppearing
method
protected override void OnAppearing ()
{
base.OnAppearing ();
nameentry.Focus();
}
这篇关于将焦点设置为Xamarin.Forms中的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!