从Xamarin Forms导航到Xamarin Native

我的问题是,我需要我的应用程序的第一页是本机。 当用户注销时,我需要一种从Xamarin Forms Content Page导航到应用程序的第一本地页面的方法。 无论如何,从一个表单页面启动本机ViewController(iOS)或启动一个活动(Android)。 我经常使用自定义渲染器。

如果我能以某种方式重新启动应用程序或再次调用AppDelegate,这将是非常好的。

任何帮助表示赞赏。

如果您定期使用自定义渲染器,则可以像这样创build自定义渲染器。 例如:

在PCL中:

public class NewView : View { } 

在Android平台中,首先在/ Resources / layout下创build一个布局,如下所示:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/tv" android:layout_height="wrap_content" android:layout_width="match_parent" android:text="this is new view." /> <Button android:id="@+id/btn" android:layout_height="wrap_content" android:layout_width="match_parent" android:text="change text" /> </LinearLayout> 

然后像这样为NewView创build渲染器:

 public class NewViewRenderer : ViewRenderer { private TextView tv; private Android.Widget.Button btn; protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e) { base.OnElementChanged(e); if (Control == null) { var context = Xamarin.Forms.Forms.Context; LayoutInflater minflater = context.GetSystemService(Context.LayoutInflaterService) as LayoutInflater; var view = minflater.Inflate(Resource.Layout.newview, this, false); tv = view.FindViewById<TextView>(Resource.Id.tv); btn = view.FindViewById<Android.Widget.Button>(Resource.Id.btn); SetNativeControl(view); } if (e.OldElement != null) { btn.Click -= Btn_Click; } if (e.NewElement != null) { btn.Click += Btn_Click; } } private void Btn_Click(object sender, EventArgs e) { tv.Text = "Text changed!"; } } 

最后在ContentPage使用这个视图来使它像一个页面:

 <ContentPage.Content> <local:NewView /> </ContentPage.Content> 

对于iOS平台,应该有一种方法将ViewController设置为视图渲染器的本机控件。 但是我对iOS不熟悉,你可以试试看。