【问题标题】:How Does Navigation in xamarin.forms Works?xamarin.forms 中的导航如何工作?
【发布时间】:2014-08-18 09:41:29
【问题描述】:

当我在 android 中为我的应用程序使用 xamarin.forms 时,我必须从一个页面导航到另一个页面。我的问题是,如果从一个页面导航到另一个页面会将其添加到导航堆栈中。例如,如果我的应用程序具有导航,例如 Page1 --> Page2 --> Page3 --> Page4 --> Page1 (它的行为类似于循环)它将替换 Page1 当我第二次导航到该页面或将其添加到堆栈中时。谁能用简单的方式解释一下导航??

编辑

我所说的替换是指如果从一个页面导航到另一个页面会将其添加到堆栈中,如果导航继续像循环一样继续并将其添加到堆栈中,它不会影响应用程序的性能吗??

注意:我不想返回上一页,只想不断地从一个页面导航到另一个页面。

提前致谢

【问题讨论】:

  • 您可以通过使用 PushModalAsync 而不是 PushAsync 来模拟这种行为
  • @Sten Petrov 您能否简要解释一下 PushModalAsyncPushAsync 导航堆栈的行为有何不同。这将非常有帮助。
  • PushModal 不会推送到导航堆栈,显示目标页面时没有“
  • 两组过渡意味着什么??
  • 看我的回答,希望对你有用

标签: android xamarin.forms


【解决方案1】:

您能否再详细说明一下这个问题?你所说的“替换”是什么意思?

这是一个堆栈,所以不:第一个 page1 不会被“替换”,而是一个“副本”。

例子:

想象一个带有绑定数据对象的列表视图。单击某个项目时,您将进入项目详细信息页面。想象一下详细信息页面有上一个和下一个按钮来导航到其他项目,然后您按一个。堆栈将如下所示:ListViewPage -> ItemsPage -> ItemsPage。

【讨论】:

    【解决方案2】:

    你说的是CarouselPage

    CarouselPage 采用多个 ContentPage 子级,并允许您向侧面滑动以切换页面。

    public class App
    {
        public static Page GetMainPage ()
        {  
            var carousel = new CarouselPage ();
            carousel.Children.Add (new ContentPage () {
                Title="One",
                Content = new BoxView {
                    WidthRequest = 90,
                    HeightRequest = 100,
                    BackgroundColor = Color.Blue
                }
            });
            carousel.Children.Add (new ContentPage () {  
                Title="TWO",
                Content = new BoxView {
                    WidthRequest = 90,
                    HeightRequest = 100,
                    BackgroundColor = Color.Red
                }
            }); 
            return carousel;
        }
    }
    

    或者,您可以在要显示的每个页面上放置两个按钮(或合适的 UI 元素)并使用 Navigation.PushModalAsync() 导航到上一页/下一页

    【讨论】:

      【解决方案3】:

      PushModalAsync 之前使用 this.Navigation.PopModalAsync () 对我有用。

      this.Navigation.PopModalAsync ();
      

      现在我的应用程序运行顺利:)

      【讨论】:

        猜你喜欢
        • 2017-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-23
        • 2017-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多