Xamarin.Forms 2.5.0 和上下文 [英] Xamarin.Forms 2.5.0 and Context

查看:32
本文介绍了Xamarin.Forms 2.5.0 和上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我更新到 Xamarin.Forms2.5.0 并看到,我收到以下警告:

  • 来自 Android 子项目:<块引用>

    警告 CS0618 'Forms.Context' 已过时:'Context 自 2.5 版起已过时.请改用本地上下文.'

如何获取本地上下文而不是 Forms.Context?Android Context 是指吗?

  • 来自自定义渲染器:<块引用>

    警告 CS0618 'ButtonRenderer.ButtonRenderer()' 已过时:'此构造函数自 2.5 版起已过时.请改用 ButtonRenderer(Context).'

在我的 ButtonRenderer 中,我只有 OnElementChanged() 方法,那么我应该在这里更改什么?只需添加一个 ButtonRenderer(Context) 构造函数?如果我在平台渲染器类中执行此操作,我仍然会收到警告.有人有例子吗?官方文档 没有提到它,谷歌也没有带来一些有用的结果,除了 ButtonRenderer 的开源代码.此更改还涉及许多其他渲染器类.

有没有人经历过其他变化,哪些刹车插件等等?

PS:我也没有发现,什么时候 Device.Windows 被弃用了.现在我用 Device.UWP 替换了它.

解决方案

我在 SearchBarRenderer 上遇到了同样的问题,我需要做的就是添加一个构造函数,如下所示:

public ShowSearchBarRenderer(Context context) : base(context){}

希望能回答您问题的第二部分.

Today I updated to Xamarin.Forms 2.5.0 and saw, that I get the following warnings:

  • From the Android sub-project:

    Warning CS0618 'Forms.Context' is obsolete: 'Context is obsolete as of version 2.5. Please use a local context instead.'

How can I get the local context instead of Forms.Context? Is the Android Context meant?

  • From the custom renderer:

    Warning CS0618 'ButtonRenderer.ButtonRenderer()' is obsolete: 'This constructor is obsolete as of version 2.5. Please use ButtonRenderer(Context) instead.'

In my ButtonRenderer I only have the OnElementChanged() method, so what should I change here? Simply add a ButtonRenderer(Context) constructor? I still get the warning, if I do this in my platform renderer class. Does anyone have an example? The official documentation doesn't mention it and Google also doesn't bring some useful results, except the open source code of ButtonRenderer. This change also concerns many other renderer classes.

Does anyone had experienced other changes, which brakes plugins and so on?

PS: Also I didn't found out, when Device.Windows was deprecated. Now I replaced it with Device.UWP.

解决方案

I had this same issue for a SearchBarRenderer and all I needed to do to fix it was add a constructor like so:

public ShowSearchBarRenderer(Context context) : base(context)
{
}

Hope that answers the second part of your question.

这篇关于Xamarin.Forms 2.5.0 和上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆