Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在OnCurrentPageChanged方法中设置选项卡页的CurrentPage属性?_C#_Xamarin_Xamarin.forms - Fatal编程技术网

C# 如何在OnCurrentPageChanged方法中设置选项卡页的CurrentPage属性?

C# 如何在OnCurrentPageChanged方法中设置选项卡页的CurrentPage属性?,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,在OnCurrentPageChanged()方法中设置选项卡页的CurrentPage属性时,出现了一些问题: 如果我使用滑动切换到符合条件的页面,应用程序将挂起 如果单击选项卡栏中的某个页面,则该页面不会更改为所需页面(据我所知,在本例中,分配是在重新分配页面之前执行的) 这应该行得通 protected override void OnCurrentPageChanged() { base.OnCurrentPageChanged(); i

在OnCurrentPageChanged()方法中设置选项卡页的CurrentPage属性时,出现了一些问题:

  • 如果我使用滑动切换到符合条件的页面,应用程序将挂起

  • 如果单击选项卡栏中的某个页面,则该页面不会更改为所需页面(据我所知,在本例中,分配是在重新分配页面之前执行的)

  • 这应该行得通

    protected override void OnCurrentPageChanged()
        {
            base.OnCurrentPageChanged();
    
                if (CurrentPage == firstPage)
                {
                    CurrentPage = secondPage;
                }
            }
        }
    

    你为什么要这么做?更改基本导航行为可能会给用户带来非常糟糕的体验。@Jason页面将显示日程安排。标签为周一、周三、周四、周五、周六、周日。我想在星期一左边做一个后退按钮,同样在周末。这将允许在两周之间导航。@Jason,或者有没有办法自定义选项卡栏以在其上放置按钮?好的,这很有趣。但不是每个页面都一样,只是数据驱动的日期不同吗?所以你真的需要告诉页面更改数据吗?@Jason是的,我需要更改页面上的数据。我在一个示例应用程序中对其进行了测试,效果良好。什么东西不起作用?活动正在进行吗?是否存在错误或异常?在第一次尝试时根本不起作用,在第二次尝试时,在无休止的循环中没有异常
        myTabs.CurrentPageChanged += Handle_CurrentPageChanged;
    
        void Handle_CurrentPageChanged(object sender, System.EventArgs e)
        {
            // you will either want to add a try/catch here, or test that 
            // Children.Count > 1 (or whatever your number of pages is) to
            // prevent this from blowing up as the tabs are initializing
                if (CurrentPage == Children[0])
                {
                    CurrentPage = Children[1];
                }
        }