Last active
August 13, 2020 14:01
-
-
Save yinyue200/a7c5fdff70bad33aff8afe733c4aadfa to your computer and use it in GitHub Desktop.
Convert Page to View on Xamarin.forms 3.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//********************************************************* | |
// | |
// Copyright (c) yinyue200.com. All rights reserved. | |
// This code is licensed under the MIT License (MIT). | |
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF | |
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY | |
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR | |
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. | |
// | |
//********************************************************* | |
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace yfxsApp.Controls.Common | |
{ | |
public class Page2View | |
{ | |
public static Xamarin.Forms.View Convert(Xamarin.Forms.Page page) | |
{ | |
#if ANDROID | |
return new Xamarin.Forms.Platform.Android.NativeViewWrapper(ConvertToNativeView(page)); | |
#elif __IOS__ | |
return new Xamarin.Forms.Platform.iOS.NativeViewWrapper(ConvertToNativeView(page)); | |
#endif | |
} | |
#if ANDROID | |
public static Android.Views.View ConvertToNativeView(Xamarin.Forms.Page page) | |
{ | |
var view = Xamarin.Forms.Platform.Android.PageExtensions.CreateFragment(page, Xamarin.Forms.Forms.Context); | |
return view.OnCreateView(Android.Views.LayoutInflater.From(Xamarin.Forms.Forms.Context), null/* new Android.Widget.FrameLayout(Xamarin.Forms.Forms.Context)*/, null); | |
} | |
#elif __IOS__ | |
public static UIKit.UIView ConvertToNativeView(Xamarin.Forms.Page page) | |
{ | |
var view = Xamarin.Forms.PageExtensions.CreateViewController(page); | |
//var vw = new UIKit.UIView(); | |
//var aa = view.View.GetType().FullName; | |
//foreach(var one in view.ChildViewControllers) | |
//{ | |
// var ss = one.GetType().FullName; | |
//} | |
view.ViewWillAppear(false); | |
//vw.AddSubview(view.View); | |
//view.ViewDidAppear(false);//我也不知道要不要加这个 | |
return view.View; | |
} | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment