首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何适应Device.OnPlataform的切换(Device.RuntimePlatform)?

如何适应Device.OnPlataform的切换(Device.RuntimePlatform)?
EN

Stack Overflow用户
提问于 2017-08-25 14:50:08
回答 1查看 214关注 0票数 2

我需要“更新”以下代码:

代码语言:javascript
复制
namespace Pizzahouse.Pages
{
public class IndexPage : ContentPage
{
    public IndexPage()
    {
        Title = "Index";

        var telephone = new Button()
        {
            Text = "Call",
            WidthRequest = 50,
        };
        telephone.Clicked += (sender, e) => Device.OpenUri(new Uri("tel://123465789"));

        Content = new ContentView()
        {
            Content = new StackLayout()
            {
                Children = {
                    new Image
                    {
                        Aspect = Aspect.AspectFit,
                        Source = Device.OnPlatform(
                            ImageSource.FromFile("PizzaIcon.png"),
                            ImageSource.FromFile("PizzaIcon.png"),
                            null)
                    }, telephone
                }
             }
        };
    }
}
}

我需要插入一个图像,但是Xamarin.Forms说Device.OnPlataform()方法过时了,它说我应该使用开关(Device.RuntimePlatform)。

这个精确的代码有效,那么你有什么建议?谢谢你的建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-25 15:04:04

代码语言:javascript
复制
Source = (Device.RuntimePlatform == Device.WinPhone) ? null : ImageSource.FromFile("PizzaIcon.png");
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45884092

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档