将焦点设置为Xamarin.Forms中的条目 [英] Setting the Focus to an Entry in Xamarin.Forms

查看:177
本文介绍了将焦点设置为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆