2

当以下代码段正在运行时(仅在用户开始时位于选项卡 [3] 的情况下),应用程序的行为会有所不同,具体取决于 CurrentPage 的更改方式:

  1. 如果用户将屏幕从选项卡 [3] 滑动到选项卡 [2],则选项卡 [3] 将按预期删除。
  2. 如果用户选择了选项卡 [0]-[2] 之一,则删除选项卡 [3]CurrentPage(正在显示)是用户选择的选项卡左侧的一个选项卡。

以前有人处理过这个吗?如果它只是一个 Xamarin 错误,有什么想法可以围绕它进行操作吗?

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);
         };
    }
}

笔记:

  • 我试图删除的选项卡是在运行时通过其中一个选项卡生成的。
  • 目前我仅在 Android 上测试了该行为。
  • 我是 Xamarin 和一般开发应用程序的初学者。事实上,这是我关于 SO 的第一个问题!
4

0 回答 0