Button没有正确的签名xamarin

时间:2016-06-28 05:48:39

标签: c# wpf xaml mvvm xamarin

我正在开发一个Xamarin.Forms项目,我遇到了这个错误,我现在几个小时都无法解决。我希望有人之前遇到过类似的问题并且可以分享他们的经验。

我得到A Xamarin.Forms.Xaml.XamlParseException was thrown

和此消息Position 23:5. Method EditInfoClicked does not have the correct signature

我的代码看起来像这样。

XAML语法:

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

和C#语法

    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 个答案:

答案 0 :(得分:6)

您无法将事件更改为 - >&gt;事件必须使用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);
    }