Loss of focus on Entry in Xamarin

Asked

Viewed 175 times

0

I’m building a mobile application with Xamarin Forms and C# where I need to check the CPF and validate the email. I am wanting to do the validations as soon as the field loses focus. I am using in my application the MVVM.

Can someone help me solve the problem?

  • 1

    In this way your question gets too wide, try to post the excerpt how you had difficulty.

1 answer

0

As @Wictorchaves said, your question is very broad. But, broadly speaking too, you can manage the event Unfocused of the component Entry.

Take an example:

Declaring via XAML

<Entry Text={Binding CampoTexto} Unfocused="Entry_Unfocused"/>

Or declaring via C#

Entry entry = new Entry();
entry.SetBinding(Entry.TextProperty, new Binding("CampoTexto"));
entry.Unfocused += Entry_Unfocused;

And the implementation of the event handler would look like this:

private void Entry_Unfocused(object sender, FocusEventArgs e)
{
    // Seu tratamento seria feito aqui
}

I hope I’ve helped.

  • Diego did. The event handler (Entry_unfocused) should be in the Behind code? There is a way to transfer it to the View Model?

  • Yes, event handler would be in the codebehind of the page. Download no. You can from the event handler, invoke a viewmodel method or command... it’s hard to tell without seeing the scenario you’re working in...

  • For example, you said in the question that you are using MVVM, but want to give treatises based on screen events (as is the case with unfocused), and that doesn’t make much sense. In MVVM you should be worried about status changes of viewmodel properties instead of screen focus events, you understand?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.