Custom renderer for Toolbar Items not working for TabbedPage

UmairEmUmairEm GBMember

Hi,

I have 2 toolbar items in tabbed page (with two tabs).

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage 
        xmlns="site wont let me post links"
        xmlns:x="hence deal with custom qualified names"
        xmlns:views="clr-namespace:TestApp.Views"
        x:Class="TestApp.Views.MyTabbedPage"
        >
    <views:Page1 Title="Page 1" />
    <views:Page 2 Title="Page 2" />
</TabbedPage>

I am trying to move one toolbar item on left using custom renderer:

assembly: ExportRenderer(typeof(MyTabbedPage), typeof(TabbedPageRenderer))]
namespace TestApp.iOS
{
    public class TabbedPageRenderer : TabbedRenderer
    {
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            var navigationItem = this.NavigationController.TopViewController.NavigationItem;
            if (navigationItem.RightBarButtonItems.Length > 1)
            {
                navigationItem.LeftBarButtonItems = new UIBarButtonItem[] { navigationItem.RightBarButtonItems[1] };
            }            
            navigationItem.RightBarButtonItems = new UIBarButtonItem[] { navigationItem.RightBarButtonItems[0]};
        }

    }
}

it works fine when page is loaded for first time. But when I click on tab to show the Page 2, It renders both toolbar items on right again (item on left stays at left) resulting in 3 toolbar items.

Can anyone please help me with this small issue?

Cheers

Sign In or Register to comment.