Xamarin.forms - How to detect enter press in entry

2019-08-27 19:44发布

问题:

I am developing an xamarin forms app based on mvvm pattern. I am looking for way to detect if user type Enter button. Event should call an command from viewModel class.

Could you guys share some tips? ;)

回答1:

Completed event is fired on press of enter key see this.

You can attach your event handler on Completed event like this:

var testEntry = new Entry ();

testEntry.Completed += (sender, e) => {

//Called on enter key press

};



回答2:

You could use an event to command behavior to bind the Completed event to a command on the view model.

Details here