简体   繁体   English

Xamarin.Forms,Xamarin.Droid更改视图

[英]Xamarin.Forms, Xamarin.Droid change view

So far, I've been unsuccessful at finding anything on this that has worked. 到目前为止,我一直没有找到任何可行的方法。 I'm trying to change the current view from a class in the .droid namespace to another in the same namespace. 我试图将当前视图从.droid命名空间中的类更改为同一命名空间中的另一个视图。

Intent intent = new Intent(this, typeof(viewclass));

Is what seems to be half correct. 似乎是正确的一半。 The biggest problem is this as I cannot do that from the droid, I get the following error: 最大的问题是这,因为我无法从droid进行操作,出现以下错误:

Cannot convert from App.Droid.CustomMapRenderer to Android.Context.Context

Solution: 解:

var intent= new Intent(Android.App.Application.Context, typeof(ViewClass));
Android.App.Application.Context.StartActivity(intent);

The biggest problem is this as I cannot do that from the droid, I get the following error: 最大的问题是这,因为我无法从droid进行操作,出现以下错误:

From the error message. 从错误消息。 You are creating an Intent inside a renderer( CustomMapRenderer ). 您正在渲染器( CustomMapRenderer )中创建一个Intent。 Thus this refers to an instance of CustomMapRenderer , but to create an intent the first argument should be a Context . 因此, this是指CustomMapRenderer的实例,但是要创建意图,第一个参数应为Context

So to fix the problem, you need to retrieve the current context in certain way, For example, you can try Intent intent = new Intent(Application.Context, typeof(viewclass)); 因此,要解决此问题,您需要以某种方式检索当前上下文,例如,可以尝试Intent intent = new Intent(Application.Context, typeof(viewclass));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM