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

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

问题描述

今天,我已更新为 Xamarin.Forms 2.5.0 并看到以下警告:

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


  • 来自Android子项目:

  • From the Android sub-project:

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

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


如何获取本地上下文而不是 Forms.Context Android上下文是什么意思?

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


  • 来自自定义渲染器:

  • From the custom renderer:

警告CS0618'ButtonRenderer.ButtonRenderer()'已过时:'此构造函数从2.5版开始已过时。请改用ButtonRenderer(Context)。'

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


在我的 ButtonRenderer 我只有 OnElementChanged()方法,所以我应该在这里更改什么?只需添加 ButtonRenderer(Context)构造函数?如果我在平台渲染器类中执行此操作,则仍会收到警告。有人有例子吗? 官方文档没有提及它,而Google除了 ButtonRenderer 的开源代码。此更改还涉及许多其他渲染器类。

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:不推荐使用 Device.Windows 时,我也没有发现。现在,我将其替换为 Device.UWP

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

推荐答案

我对于 SearchBarRenderer 遇到了同样的问题要解决该问题,需要添加一个构造器,如下所示:

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天全站免登陆