Button does not have the correct signature xamarin

2019-06-10 16:30发布

问题:

I'm working on a Xamarin.Forms project and I've had this error I cant solve for hours now. I'm hoping that someone has experienced a similar problem previously and can share their experience.

I get A Xamarin.Forms.Xaml.XamlParseException was thrown

and this message Position 23:5. Method EditInfoClicked does not have the correct signature

My code looks like this.

XAML Syntax:

    <StackLayout x:Name="_MapStack">
    <Button BackgroundColor="#40A6FF" 
            WidthRequest="100"
            BorderRadius="3" 
            Text="Edit" 
            FontSize="16" 
            TextColor="White"
            Clicked="EditInfoClicked" />

And C# Syntax

    async Task EditInfoClicked(object sender, EventArgs e)
    {
        ProfileDetailViewModel viewModel = new 
        ProfileDetailViewModel (Navigation, user);
        var profileDetailPage = new shared.MyProfilePage()

        {
            BindingContext = viewModel
        };

        await Navigation.PushAsync(profileDetailPage);
    }

回答1:

You cant have Task for events change to -> events will have to use async void

async void EditInfoClicked(object sender, EventArgs e)
    {
        ProfileDetailViewModel viewModel = new 
        ProfileDetailViewModel (Navigation, user);
        var profileDetailPage = new shared.MyProfilePage()

        {
            BindingContext = viewModel
        };

        await Navigation.PushAsync(profileDetailPage);
    }