Windows 10 SplitView Hamburger Menu

The new control SplitView added in Windows 10 and are used to display side menu. Many of them called IT hamburger menu. Two things we need to know “Pane” and “Content”.

Pane

These properties contain the menu buttons in your app.

Content

The page content goes in this area.

  1. <SplitView>  
  2.     <SplitView.Pane> //Add your menu here </SplitView.Pane>  
  3.     <SplitView.Content> //Add your content here </SplitView.Content>  
  4. </SplitView>  
Using “IsPaneOpen” property you can set true or false, true for open and false to close.

Now create a new Windows 10 project and give proper name. After that open your Mainpage.xaml and you can see the empty Grid control as in the following screenshot,

Code

Delete this grid and paste the following code:
  1. <SplitView x:Name="MyMenu" DisplayMode="CompactOverlay" IsPaneOpen="False" CompactPaneLength="50" OpenPaneLength="150">  
  2.     <SplitView.Pane>  
  3.         <StackPanel Background="Gray">  
  4.             <Button x:Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content="" Click="HamburgerButton_Click" />  
  5.             <Button x:Name="button1" FontFamily="Segoe MDL2 Assets" Content=""></Button>  
  6.             <Button x:Name="button2" FontFamily="Segoe MDL2 Assets" Content=""></Button>  
  7.             <Button x:Name="button3" Content="Next Page" Click="button3_Click"></Button>  
  8.         </StackPanel>  
  9.     </SplitView.Pane>  
  10.     <SplitView.Content>  
  11.         <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">  
  12.             <TextBlock Text="Hamburger Menu Demo" TextAlignment="Center" VerticalAlignment="Center"></TextBlock>  
  13.         </Grid>  
  14.     </SplitView.Content>  
  15. </SplitView>  
In the above code we are creating the button in menu and styling to hamburger menu. We don’t need to add icons for button, just change the Font family to “Segoe MDL2 Assets” and set the content (cheat code) as your wish to see more icons cheat sheet codes.

For example, I set the content as “&#E700;” and it shows like the following image.

Menu bar

Now you can create button as per your need. Here I created 4 buttons for sample.

Finally, go to code behind page and I have one button click event to close and open the split view. In handler we simply want to set pane to close if it is open and vice versa like the following code.
  1. private void HamburgerButton_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.    MyMenu.IsPaneOpen = !MyMenu.IsPaneOpen;  
  4. }  
  5.   
  6. private void button3_Click(object sender, RoutedEventArgs e)  
  7. {  
  8.    Frame.Navigate(typeof(Page1))  
  9. }  
Now run the app and see the excepted output like the following screen.

For source code.

run

Menu

 


Similar Articles