【问题标题】:xamarin OnPlatform for clicked button用于单击按钮的 xamarin OnPlatform
【发布时间】:2019-07-29 10:33:49
【问题描述】:

我现在可以在 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 次点击事件?

【问题讨论】:

  • @SushiHangover 你能告诉我怎么做吗?我正在尝试连接到 mysql,所以对于 android 和 ios,我正在使用 System.Data.CData.MySQL;对于使用 MySql.Data.MySqlClient 的 uwp;

标签: c# xamarin


【解决方案1】:

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

示例:

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;
    }
}

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

【讨论】:

    猜你喜欢
    • 2017-12-14
    • 1970-01-01
    • 2021-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-09
    • 1970-01-01
    相关资源
    最近更新 更多