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

查看:29
本文介绍了将焦点设置为 Xamarin.Forms 中的条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这只是一个简化的示例,但我正在尝试进行设置,以便当我在我的应用程序中打开此页面时,发生的第一件事是键盘弹出准备好让用户输入他们的响应到一个条目字段.

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?

推荐答案

使用Focus方法

nameentry.Focus();

如果您希望在页面出现时设置焦点,您可能应该在 OnAppearing 方法中执行此操作

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天全站免登陆