我目前正在做一个实习项目,需要我使用一个过时的项目。 我仍在尝试构建项目,消除了所有错误,但现在这些过时行的警告不允许我通过。
我有以下错误:
Warning CS0618 'Device.OnPlatform(T, T, T)' is obsolete: 'OnPlatform<> (generic) is obsolete as of version 2.3.4. Please use switch(RuntimePlatform) instead.'
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace MobileMedico.Classes
{
public static class BoolResources
{
public static readonly bool ShouldShowBoxView = Device.OnPlatform(true, false, true);
}
}
遗憾的是我不知道如何使用 Switch
方法。谁能帮帮我?
最佳答案
是的,该方法现在已过时。为了针对特定设备,您确实必须使用将运行时平台作为参数的 switch 语句。这是一个示例。
static class AppConstants
{
public static readonly Thickness PagePadding = GetPagePadding();
private static Thickness GetPagePadding()
{
double topPadding;
switch(Device.RuntimePlatform)
{
case Device.iOS:
topPadding = 20;
break;
default:
topPadding = 0;
break;
}
return new Thickness(5, topPadding, 5, 0);
}
}
关于android - Device.OnPlatform 和 Switch() 之间的 Xamarin 应用混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49497404/