2

While the following snippet is running (only in case the user is on tab [3] to begin with), the app acts differently depending the way the CurrentPage was changed:

  1. If the user swiped the screen from tab [3] to tab [2], tab [3] is removed as expected.
  2. If the user selected one of the tabs [0]-[2], tab [3] is removed but CurrentPage (that is being displayed) is one tab to the left of the tab that the user selected.

Does anyone dealt with this before? If it's simply a Xamarin bug, any ideas how to manipulate around it?

public partial class MainPage : TabbedPage
{
    public MainPage()
    {
        InitializeComponent();
        //Some logic...

        ///Max number of tabs = 3, unless CurrentPage is the 4th tab.
        ///When CurrentPage is no longer the 4th tab, it will be removed.
        this.CurrentPageChanged += (object sender, EventArgs e) =>
        {
             if ((CurrentPage == this.Children[0] || CurrentPage == this.Children[1] ||
                   CurrentPage == this.Children[2]) && this.Children.Count > 3)
                 this.Children.RemoveAt(3);
         };
    }
}

Notes:

  • The tab that I'm trying to remove is generated on runtime via one of the tabs.
  • Currently I tested the behavior only on Android.
  • I'm a beginner to Xamarin and to apps developing in general. In fact, this is my first question on SO!
Ofaim
  • 41
  • 3

0 Answers0