Before reading this article, please go through the article's link, given below-
The following important tools are required to develop UWP-
- Windows 10 (Recommended).
- Visual Studio 2015 Community Edition (It is a free software available online).
Now, we can discuss the app development, by following the steps, given below-
Step 1: Open Visual Studio 2015 -> Start -> New Project-> Select Universal (under Visual C#->Windows)-> Blank App -> Give the Suitable name for your App (UWPHubApp) ->OK.

Step 2: Choose Target and minimum platform version for your Windows Universal Application will support. Afterwards, the project creates App.xaml and MainPage.xaml.

Step 3: Open (double click) the file MainPage.xaml in the Solution Explorer and click the Toolbox tab on the left to open the list of Common XAML controls. Expand Common XAML Controls and drag the required control to the middle of the design canvas.
Add the Hub control and change the Name property and Header property. While adding Hub control, automatically two Hub sections are also added to our project.
Now, we can change the Hubsection 1 Name, Header property and enable the IsHeaderInteractive property.
Set Assets images to HSec1. Similarly, add images to All sections.
Note: Automatically, the following code will be generated in XAML code view, while we are done in the design view-
- <Page x:Class="UWPHubApp.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:UWPHubApp" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
- <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
- <Hub x:Name="MYHub" Header="Hub Test" SectionHeaderClick="MYHub_SectionHeaderClick">
- <HubSection x:Name="HSec1" Header="Sec 1" IsHeaderInteractive="True">
- <DataTemplate>
- <Grid>
- <Image Source="/Assets/02.jpg" Stretch="UniformToFill" /> </Grid>
- </DataTemplate>
- </HubSection>
- <HubSection x:Name="HSec2" Header="Sec 2" IsHeaderInteractive="True">
- <DataTemplate>
- <Grid>
- <Image Source="/Assets/03.jpg" Stretch="UniformToFill" /> </Grid>
- </DataTemplate>
- </HubSection>
- <HubSection x:Name="HSec3" Header="Sec 3" IsHeaderInteractive="True">
- <DataTemplate>
- <Grid>
- <Image Source="/Assets/04.jpg" Stretch="UniformToFill" /> </Grid>
- </DataTemplate>
- </HubSection>
- <HubSection x:Name="HSec4" Header="Sec 4" IsHeaderInteractive="True">
- <DataTemplate>
- <Grid>
- <Image Source="/Assets/05.jpg" Stretch="UniformToFill" /> </Grid>
- </DataTemplate>
- </HubSection>
- </Hub>
- </Grid>
- </Page>
Step 6: Add the code, given below, to MYHub_SectionHeaderClick method in MainPage.xaml.cs. This code is used to navigate next HubSections.
- switch (e.Section.Name)
- {
- case "HSec1":
- MYHub.ScrollToSection(HSec2);
- break;
- case "HSec2":
- MYHub.ScrollToSection(HSec3);
- break;
- case "HSec3":
- MYHub.ScrollToSection(HSec4);
- break;
- case "HSec4":
- MYHub.ScrollToSection(HSec1);
- break;
- default:
- MYHub.ScrollToSection(HSec1);
- break;
- }


Summary: Now, you successfully created and tested your Hub Control in Visual C# - UWP environment.

Girish cPosted Jun 3, 2021, 10:16 AM
Hi team, I Have Hub Control in XAML and Mutiple HubSections and I Need to navigate to Different HubSection using MVVM lite and I know How to do it I code Behind, but as I am using MVVM , I need to do it using MVVM