xamarin OnPlatform的单击按钮

时间:2019-07-29 01:21:06

标签: c# xamarin

我现在可以在xamarin上使用OnPlatform

    <button text="{OnPlatform android=Hi , uwp=bey"}/>

但是,如果我想在点击的对象上使用它,就像:

     <button clicked="{OnPlatform android=Android_klik , uwp=Wpf_klik"}/>

那我有这个错误:

     Severity   Code    Description Project File    Line    Suppression State
     Error      Position 16:34. No property, bindable property, or event found for 'Clicked', or mismatching type between value and property.   $$  $$\MainPage.xaml

那么我可以在xaml上创建2 click事件吗?

1 个答案:

答案 0 :(得分:0)

您可以在switch属性上使用if(或else / Device.RuntimePlatform)。

示例:

void someButton_Click_Handler(object sender, EventArgs args)
{
    switch (Device.RuntimePlatform)
    {
        case Device.UWP:
            // do your UWP assignments...
            break;
        default:
            // do your Android & iOS assignments...
            break;
    }
}

re:https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.device.runtimeplatform?view=xamarin-forms#Xamarin_Forms_Device_RuntimePlatform