Use Hamburger Menu In UWP Application

Here are the steps: 

Step 1: Create a new Universal Windows Project and name it whatever you want.



Step 2:

Now go to the MainPage.xaml and define your rows in the Grid by using Grid.RowDefination and assign a height to these rows. In our case we have created two rows of Height auto and *. 

  1. <Grid.RowDefinitions>  
  2.   
  3.     <RowDefinition Height="auto" />  
  4.   
  5.     <RowDefinition Height="*" />  
  6.   
  7. </Grid.RowDefinitions>  

Step 3:

Once you've done with your rows add splitview in your app by using SplitView and the following lines of code. The first row in which you define height property to auto is for RelativePanel and hamburger button and the next row is for the listbox and listboxitems.

Here's the code for that,

  1. <RelativePanel>  
  2.   
  3.     <Button Width="60" Height="45" Name="hamburgerbtn" Click="hamburgerbtn_Click" FontFamily="Segoe MDL2 Assets" Content="" Margin="0,30,0,0"></Button>  
  4.   
  5. </RelativePanel>  
  6.   
  7.   
  8. <SplitView Grid.Row="1" Name="mysplitview1" DisplayMode="CompactOverlay" OpenPaneLength="300" CompactPaneLength="60">  
  9.   
  10.     <SplitView.Pane>  
  11.   
  12.         <ListBox>  
  13.   
  14.             <ListBoxItem>  
  15.   
  16.                 <StackPanel Orientation="Horizontal">  
  17.   
  18.                     <TextBlock FontSize="45" FontFamily="Segoe MDL2 Assets" Text=""></TextBlock>  
  19.   
  20.                     <TextBlock Margin="30,0,0,0" FontSize="25" Text="Search something"></TextBlock>  
  21.   
  22.   
  23.                 </StackPanel>  
  24.   
  25.             </ListBoxItem>  
  26.   
  27.             <ListBoxItem>  
  28.   
  29.                 <StackPanel Orientation="Horizontal">  
  30.   
  31.                     <TextBlock FontSize="45" FontFamily="Segoe MDL2 Assets" Text=""></TextBlock>  
  32.   
  33.                     <TextBlock Margin="30,0,0,0" FontSize="25" Text="Record something"></TextBlock>  
  34.   
  35.   
  36.                 </StackPanel>  
  37.   
  38.             </ListBoxItem>  
  39.   
  40.         </ListBox>  
  41.   
  42.     </SplitView.Pane>  
  43.   
  44. </SplitView>  

Notice that you don't need to add some additional hamburger images in your Assets because in Visual Studio 2015 you just add your icon code by going into windows start and and enter character map the windows 10 Cortana opens it for you. Now what you need you just go to the font Segoe MDL2 Assets and find your icon whatever you want and paste this code in your xaml editor of visual studio 2015.

Step 4 :

Now we move to some backend c-sharp code for achieving better functionality. So behind the button add some code in button click event handler of Mainpage.xaml.cs i.e.,

  1. private void hamburgerbtn_Click(object sender, RoutedEventArgs e)  
  2.   
  3. {  
  4.   
  5.     mysplitview1.IsPaneOpen = !mysplitview1.IsPaneOpen;  
  6.   
  7. }  

Step 5 :

Save all and run your project by just pressing F5.

A splash screen will open up after this your hamburger menu or simply called split view is open. You can check or open your listitems by pressing the hamburger button.

Up Next
    Ebook Download
    View all
    Learn
    View all