【问题标题】:Return to proper hubsection when returning to mainpage返回主页时返回正确的中心部分
【发布时间】:2015-04-14 19:17:36
【问题描述】:

我正在创建一个 Windows Phone 8.1 应用程序,我的主页有一个 Hub 控件,该控件由一个(手动创建的)XAML hubsection 和多个从 JSON 生成的动态 hubsections 组成。我有一个将用户带到新页面的按钮。当用户返回主页时,它当前向用户显示第一个集线器部分。我正在努力让用户返回并看到之前关注的中心部分。

我尝试过:

        IList<HubSection> currentSections;
        currentSections = mainHub.SectionsInView;
        // Do your code
        mainHub.SectionsInView = currentSections;

但显然SectionsInView 是只读的。我在网上找不到任何东西...有没有办法做到这一点?

【问题讨论】:

    标签: c# xaml windows-phone windows-phone-8.1


    【解决方案1】:

    尝试使用Hub.ScrollToSection 方法或 Hub.DefaultSectionIndex 属性

    【讨论】:

    • 我决定使用 Hub.ScrollToSection 并且我通过 Frame.Navigate(page, HubSection) 将选定的 HubSection 通过页面传递并在 OnNavigatedTo 方法中获取它 ((HubSection)e.Parameter )。这样做它不会选择我想要的部分(停留在第一页)......但是如果我将它硬编码到 Hub.ScrollToSection(Hub.Sections[1]) 它可以工作......有没有办法通过 hubsection它仍然有效吗?我不想使用索引,因为它可能会改变。
    • 您可以迭代 Hub.Sections 集合以找到您想要的部分,然后将其传递给 ScrollToSection
    • 这就是我决定做的...希望有更好的方法,非常感谢:)
    猜你喜欢
    • 1970-01-01
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    • 1970-01-01
    • 2014-07-24
    • 2013-11-23
    相关资源
    最近更新 更多