Error "Eventhandler with correct Signature not found"

Asked

Viewed 112 times

-1

I have the main page and Contentpage inside the Views folder. Content is successfully loaded.

<Tab Title="Entrar In" Icon="enter.png">
    <ShellContent ContentTemplate="{DataTemplate local:Entrar}" />
</Tab>

Inside this Contentpage I have a button to execute the login

<Button Text="Entrar" Clicked="DoLogin" />

Login method

public async void DoLogin(object sender, EventArgs e)
        {
            var UserLogin = new UserLogin
            {
                email = emailLogin.Text,
                password = passwordLogin.Text
            };

            try
            {
                using (var httpClient = new HttpClient())
                {
                    var dataUser = JsonConvert.SerializeObject(UserLogin);
                    HttpContent requestContent = new StringContent(dataUser, Encoding.UTF8, "application/json");
                    httpClient.DefaultRequestHeaders.Add("Locale", CultureInfo.CurrentCulture.Name);
                    var requestResponse = await httpClient.PostAsync("endereço", requestContent);

                    if (requestResponse.IsSuccessStatusCode)
                    {
                        ....
                    }
                    else
                    {
                        await Application.Current.MainPage.DisplayAlert("", "Desculpe, houve uma falha na sua requisição.", "OK");
                    }
                }
            }
            catch (Exception)
            {
                await Application.Current.MainPage.DisplayAlert("", "Desculpe, houve uma falha na sua requisição.", "OK");
            }
        }

The fault (I’m sure I’m missing some "link" by is starting in this language) occurs because the Login method is inside the User class that is inside the Models folder.

inserir a descrição da imagem aqui

  • Display your login method

  • Before moving the login method to the Models/ User class folder, I was able to log in.

  • You just moved or moved and corrected the namespaces? By the code presented now, you should be getting a different error message...

  • I added using Myapp.Models and using Myapp.Views inside Appshell.xaml.Cs and xmlns:local="clr-namespace:Myapp.Views" inside Appshell.xaml. I have not added reference to Myapp.Models within Appshell.xaml.

  • And as the button with the event DoLogin() will know that he needs to make this bind searching for the method in class User ?

  • This is the point, I tried to make this bind using Icommand and it didn’t work either.. I’m searching but still haven’t found how to do it.

  • It is a little confused and broad, I think you will have review its structure. Incidentally the DoLogin() should not be in the Services instead of Models?

  • If I go back and put the whole structure within the same shampoo it works, but I would like to follow the good rules and also learn. I’m really going to migrate into Services right now and.. I’ll do it right now and tell you whether it worked or not.

  • I created a View with the methods and made a contextpage Bind, <Contentpage.Bindingcontext> <vm:Userviewmodel /> </Contentpage.Bindingcontext>. But the Bind of the login and password fields for registration gives the error: [0:] Binding: 'Emaillogin' Property not found on 'Myapp.ViewModels.Userviewmodel', target Property: 'Xamarin.Forms.Entry.Text' . Within Entry I used Text="{Binding Passwordlogin}" and userViewModel.Cs public string Emaillogin { get; }

  • Details, I had to create public Icommand Dologin {get;} and when I click the button to send execute Dologin = new Command(Login). The method to login is the public async void Login(Object Parameter)

  • Solved then? It would be nice to post the answer showing how you did so you can help other users in the future.

  • I will update yes. but still have to solve the Binding problem of the login and password fields.. Today I will analyze and update the post..

Show 7 more comments

1 answer

0

To execute the login method I used Command giving a Binding button.

<Button Command="{Binding DoLogin}"/>

Inside Viewmodel I used Icommand and called the Login method

public ICommand DoLogin { private set; get; }  

public UserViewModel()
{
   DoLogin = new Command(Login);
}

Browser other questions tagged

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