Skip to main content

How to create app bar with menu windows 8 (Windows Store apps using C# and XAML)

Hi Guys..
These days i am interesting in windows 8 app developing because i have to create 20 windows 8 apps for Microsoft student champs .So i decided to create series of post "How to Create windows 8 app".
Actually i am not going to start this in beginner level but if you requested then i can consider about it.  Lets go to the my fist post in "How to Create windows 8 app"


When you add commands to an app bar, consider whether your command sets would work better in a command menu. Menus let you present more options in less space and include interactive controls. In this example, the Sort menu pops up a simple list that makes choosing options easy.


Step 1: Add an app bar to the app

  • Add an app bar to your app.Here, we add a bottom app bar with a button to show the sort menu.
 <Page.BottomAppBar>  
   <AppBar x:Name="bottomAppBar" IsSticky="True">  
     <Grid>  
       <StackPanel x:Name="rightPanel"   
             Orientation="Horizontal" HorizontalAlignment="Right">  
         <Button Style="{StaticResource AppBarButtonStyle}"   
             Content="&#xE174;"   
             AutomationProperties.Name="Sort"  
             AutomationProperties.AutomationId="SortButton"  
             Click="SortMenuButton_Click" />  
       </StackPanel>  
     </Grid>  
   </AppBar>  
 </Page.BottomAppBar>  


Step 2: Show the menu pop up

When a user clicks the Sort command button on the AppBar, you show a Popup menu. The user picks a sort option from the menu.

  1. Create a Popup to host the sort menu.
  2.  Popup popUp = new Popup();  


  3. Set the Popup.IsLightDismissEnabled property to true.
    With light dismiss enabled, the Popup hides automatically when the user interacts with another part of the app.
  4.  popUp.IsLightDismissEnabled = true;  
    


  5. Create a panel as the root of the menu UI.
  6.  StackPanel panel = new StackPanel();  
     panel.Background = bottomAppBar.Background;  
     panel.Height = 140;  
     panel.Width = 180;  
    


  7. Add command buttons to the menu UI.
  8.  Button byRatingButton = new Button();  
     byRatingButton.Content = "By rating";  
     byRatingButton.Style = (Style)App.Current.Resources["TextButtonStyle"];  
     byRatingButton.Margin = new Thickness(20, 5, 20, 5);  
     byRatingButton.Click += SortButton_Click;  
     panel.Children.Add(byRatingButton);  
    


  9. Add the menu root panel as the Popup content.
  10.  popUp.Child = panel;  
    


  11. Calculate the placement of the Popup menu.
    Here, we place the Popup in the bottom right corner of the screen, above the AppBar, with a padding of 4.
  12.  popUp.HorizontalOffset = Window.Current.CoreWindow.Bounds.Right - panel.Width - 4;  
     popUp.VerticalOffset = Window.Current.CoreWindow.Bounds.Bottom - bottomAppBar.ActualHeight - panel.Height - 4;  
    


  13. Open the Popup.
  14.  popUp.IsOpen = true;  
    


    Thank You Guys :)

Comments

Popular posts from this blog

Multithreading C# : Part 01

Multithreading with C# Think about old days, you have one central processing unit (CPU) in your pc which is capable of executing one operation at a time. If we have 5 operations to run then we have to wait till one operation is completed and then only other one can start. What will happen if the running operation has a bug and got stuck, then whole computer going to be freeze and useless unless we restart it. This is a huge problem. So if we can run multiple operation in the same time that would be great because it will solve this problem.

Load an Addin into DraftSight

These days i am developing two plugins for Autocad 2012 &  DraftSight 2013.so when i was developing the plugin i got in to big trouble.Normally in the Autocad , we can load the .dll file simply typing the command "NETLOAD" but in the Draftsight i could not able to do that. It said  " D:\c \projects\c projects\DSAddinCSharp1\ DSAddinCSharp1\bin\Debug\ DSAddinCSharp1.dll is not a valid add-in "

Start button confirmed to make a comeback in Windows 8.1

We first  heard rumors  about a possible comeback of the Start menu button in Windows 8.1 last week, but now sources speaking to  The Verge  have confirmed that this will indeed be the case, only it’s probably not what most detractors were hoping for. The newly reintroduced button will reportedly sit on the traditional bottom left corner, and will look near-identical to the existing Windows flag used in the Charm bar, but clicking on it will simply bring up the tile-based Start screen rather than the old Start menu. Read Full Article