Showing different toolbar buttons on each page with Xamarin Forms

前端 未结 2 1705
时光取名叫无心
时光取名叫无心 2021-01-13 17:21

I have 2 pages in my Xamarin Forms app. My first page has 4 icons in the toolbar. My second page is a login page and has a tick and a cross in the toolbar.

I can\'t

2条回答
  •  失恋的感觉
    2021-01-13 17:31

    One option that you have, and one that I implemented in my own app, is a custom renderer that removes the navigation header from the app and then you could build your own custom header. With this approach, you do lose some of the native feel of the app, and you have to implement much of the transitional functionality your self. However, it gives you alot more control over the look.

    CustomRenderer that removes the navigationBar:

    //add using statements
    
    // add all view here that need this custom header, might be able to build a 
    //base page that others inherit from, so that this will work on all pages.
    [assembly: ExportRenderer(typeof(yourView), typeof(HeaderRenderer))] 
    
    class HeaderRenderer : PageRenderer
    {
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);
            this.NavigationController.SetNavigationBarHidden(true, true);
        }
    }
    

    After this you can build a header view that can be placed on the top of every page (I am using xaml) so I don't know if it is relevant in you application.

    Edit: You might need to change this renderer for differnt page types.

提交回复
热议问题