Reputation: 1648
I want to fire a keypress event like ENTER
and trigger my method but I can't find any reference about doing a keypress event in xaml and call it on my view model
Could someone throw some reference. Please thanks.
Upvotes: 1
Views: 11421
Reputation: 364
An input view (Entry or Editor) has to show the Keyboard first, therefore handle the TextChanged event of the input view.
First attach the event:
public MainPage()
{
InitializeComponent();
txtEntry.TextChanged += TxtEntry_TextChanged;
}
Then handle the event
void TxtEntry_TextChanged(object sender, Xamarin.Forms.TextChangedEventArgs e)
{
txtEntry.TextChanged -= TxtEntry_TextChanged;
char key = e.NewTextValue?.Last() ?? ' ';
if (key == 'A')
{
//do something
}
txtEntry.TextChanged += TxtEntry_TextChanged;
}
Upvotes: 1