Xamarin-Sidebar icon indicating copy to clipboard operation
Xamarin-Sidebar copied to clipboard

Blank menu content when used with Xamarin Forms

Open johnnysbug opened this issue 10 years ago • 4 comments

Here's how I am setting up the SideBarController for one of my Xamarin Forms pages (via a renderer):

My Renderer:

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var nativeView = NativeView;
            if (nativeView != null)
            {
                var rootViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
                Sidebar = new SidebarController(rootViewController, this, new MenuViewController());
            }
        }

When I slide the menu out, it is a blank white view. I've tried other options, like just newing up a view controller and passing that in as the root view controller, but I see the same results. I've tried moving this code to the OnElementChanged method, but still the same problem.

Have you or anyone else had any success when integrating with Xamarin Forms?

johnnysbug avatar Aug 06 '15 18:08 johnnysbug

I have had success in another renderer, but only because the content view controller was pulled from a Storyboard, like so:

        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            var hostViewController = ViewController;

            var storyboard = UIStoryboard.FromName("Main_iPhone", null);
            var viewController = storyboard.InstantiateViewController("MyTabBarController") as MyTabBarController;

            Sidebar = new SidebarController(this, viewController, new MenuViewController());

            hostViewController.AddChildViewController(viewController);
            hostViewController.View.Add(viewController.View);

            viewController.DidMoveToParentViewController(hostViewController);
        }

The above does work and I can see menu content. However, in my other renderer, the content view is an actual XF Page.

johnnysbug avatar Aug 06 '15 18:08 johnnysbug

In my app I got the same behaviour with the following code:

var formsPage = (Page)this.Element;
//var navigationController = new UINavigationController { NavigationBarHidden = true };
//navigationController.PushViewController(formsPage.CreateViewController(), false);
var sidebarController = new SidebarNavigation.SidebarController(
                                        formsPage.CreateViewController(), this, new SideMenuController());

eusebiu avatar Jan 16 '16 19:01 eusebiu

I have a working example using Xamarin Forms here: https://github.com/jdehlin/Xamarin-Sidebar/tree/master/XamarinFormsSample

Have you taken a look at that?

jdehlin avatar Jan 19 '16 14:01 jdehlin

Yes, but the difference is that in your samples you are new-ing a ContentController or a page and then create a view controller. In my code I am using an existing formsPage and then call the CreateViewController in the renderer.

eusebiu avatar Jan 22 '16 09:01 eusebiu