Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

custom renderer navigation bar disappears

$
0
0

For my project I needed to have something to the effect of a master detail page but with the possibility of a sliding menu on either side of the screen. So I wrote my own and added custom renderers.
And for the most part this works fine, the only oddity is the navigation bar. On iOS it has stopped responding to inputs, I can still see the back button but it no longer does anything and on Android it has disappeared alltogether. Now, my understanding of the navigation bar is that it is tied to a navigation page, as long as you're using a navigation page as "root" you should be fine. Right?

The custom page I wrote extends from MultiPage btw, if that makes any difference.

So my view tree looks like this:

  • CustomPage:

    • leftMenu
    • NavigationPage:

      • DetailPage (<= this one gets swapped out when switching views)
    • rightMenu

The code I use to initialize it is this:

`var viewFactory = container.Resolve();

            var mainPage = viewFactory.Resolve<MainViewModel>();                
            var navigation = new NavigationPage(mainPage)
            {
                BarBackgroundColor = Color.Green,
                BarTextColor = Color.White
            };

            var leftMenu = viewFactory.Resolve<LeftMenuViewModel>();
            var rightMenu = viewFactory.Resolve<RightMenuViewModel>();
            var root = new MasterDetailMasterPage(leftMenu, navigation, rightMenu);


            navigation.ToolbarItems.Add(new ToolbarItem("nogeentest", "nx", () => { }));
            mainPage.ToolbarItems.Add(new ToolbarItem("maintest", "nx", () => { }));
            root.ToolbarItems.Add(new ToolbarItem("youwot", "icon.png", () => { }));

            _application.MainPage = root;`

If I make even a slight alteration and, instead, use a MasterDetail page from xamarin forms itself like so:

`var viewFactory = container.Resolve();

            var mainPage = viewFactory.Resolve<MainViewModel>();                
            var navigation = new NavigationPage(mainPage)
            {
                BarBackgroundColor = Color.Green,
                BarTextColor = Color.White
            };

            var leftMenu = viewFactory.Resolve<LeftMenuViewModel>();
            var rightMenu = viewFactory.Resolve<RightMenuViewModel>();
            var root = new MasterDetailPage(){
        Master = rightMenu,
        Detail = leftMenu
    };
            _application.MainPage = root;`

then all is fine while the view tree hasn't really changed that much:

  • MasterDetailPage:

    • rightMenu
    • NavigationPage:

      • DetailPage

I haven't been able to find all that much about it and I'm currently out of ideas as to what I'm supposed to do.

Do I need to code it myself inside the renderers? Am I missing a piece of initialization code? Something else perhaps?
I don't know.

All input is appreciated.

edit: alright, i found something peculiar.

If I changed the viewtree to

  • navigationpage

    • CustomPage

      • leftMenu
      • rightMenu
      • navigationpage

        • Detail

then it works, but only in one direction. The moment I press the back key to go back to the mainscreen an exception gets thrown stating that only 1 navigationpage is allowed to be on the screen at any given time.
Strange stuff...


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>