Regarding with call a stortyboard from a content page from PCL

hello community!

I have a project done almost 90% in xamarin forms, using only the project PCL, at this moment I have to have a page of reports, in which I will have to use a native lirberia for iOS, for that I will have to from my content To call a story board that contains the full report, I need that this does not appear as a popup modal, but instead occupies the full screen as if it were a content page of xamarin forms, in addition to being able to return to the previous content page.

Anyone have any ideas to do this?

Best Answer

  • LandLuLandLu Xamurai
    Accepted Answer

    Firstly, create a blank page in Forms:

    public class BlankPage : ContentPage
    {
        public BlankPage()
        {
    
        }
    }
    

    Secondly, define a custom renderer in iOS for this page. Then embed your storyboard page there:

    [assembly: ExportRenderer(typeof(BlankPage), typeof(CustomPageRenderer))]
    namespace App.iOS
    {
        public class CustomPageRenderer : PageRenderer
        {
            protected override void OnElementChanged(VisualElementChangedEventArgs e)
            {
                base.OnElementChanged(e);
    
                if (e.NewElement != null)
                {
                    var storyboard = UIStoryboard.FromName("Main", null);
                    var controller = storyboard.InstantiateViewController("ViewController");
                    NativeView.AddSubview(controller.View);
                    ViewController.AddChildViewController(controller);
                }
            }
        }
    }
    

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai
    Accepted Answer

    Firstly, create a blank page in Forms:

    public class BlankPage : ContentPage
    {
        public BlankPage()
        {
    
        }
    }
    

    Secondly, define a custom renderer in iOS for this page. Then embed your storyboard page there:

    [assembly: ExportRenderer(typeof(BlankPage), typeof(CustomPageRenderer))]
    namespace App.iOS
    {
        public class CustomPageRenderer : PageRenderer
        {
            protected override void OnElementChanged(VisualElementChangedEventArgs e)
            {
                base.OnElementChanged(e);
    
                if (e.NewElement != null)
                {
                    var storyboard = UIStoryboard.FromName("Main", null);
                    var controller = storyboard.InstantiateViewController("ViewController");
                    NativeView.AddSubview(controller.View);
                    ViewController.AddChildViewController(controller);
                }
            }
        }
    }
    
Sign In or Register to comment.