Search code examples
windows-phone-8windows-phone-8.1

Programmatically change HubSection Windows Phone


Is it possible to change a Hubsection as if you moved it with your finger per code? E.g. I have three HubSections, I click a button in HubSection3 and it changes to HubSection1.


Solution

  • If you assign both your hub and your sections names, then in your code-behind you can do something like this:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        MyHub.ScrollToSection(HubSection1);
    }
    

    However from a UI perspective, I personally wouldn't drive the navigation with a button in this way. As generally, the purpose of a hub is to display content in a similar style to that of a magazine, allowing the user to flick through the content at their discretion.