我的Xamarin表单EditText事件FocusChange将不会触发

时间:2018-07-23 18:40:59

标签: xamarin xamarin.forms

当EditText获得焦点时,我想在此字段中选择所有输入的文本。 在文件后面的代码中,我有:

    private EditText _scanItem;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Set our view from the "inventory" layout resource
        SetContentView(Resource.Layout.inventory);

         _scanItem = FindViewById<EditText>(Resource.Id.editText1);

        _scanItem.FocusChange += _scanItem_FocusChange;
     }

             private void _scanItem_FocusChange(object sender, Android.Views.View.FocusChangeEventArgs e)
    {
        if (_scanItem.HasFocus == true)
            _scanItem.SelectAll();
        //throw new NotImplementedException();
    }

任何帮助将不胜感激。预先感谢!

1 个答案:

答案 0 :(得分:0)

请改为使用_scanItem.SetSelectAllOnFocus(true);

完成!