ApplicationBar控件时windows phone 7上的一个菜单,它传统的Windows程序的菜单的作用类似。
ApplicationBar(ApplicationBarIconButton和ApplicationBarMenuItem)相关的类定义在Microsoft.Phone.Shell命名空间。与UIElement和FrameworkElement等常规Silverlight编程的类层次是完全分开的,严格说来ApplicationBar不是你的页面的可视化的一部分。
一个ApplicationBar最多可包含四个按钮。如果还有额外的选项可以通过菜单项来添加,这些菜单项默认是不显示的。只有在点击菜单栏右侧的省略号(或省略号下方的区域)时才会显示出来。

该项目包含一个MediaElement MoviePlayer播放影片,而ApplicationBar包含第一,播放,暂停,最后四个选项。

 

Windows Phone 7 程序菜单栏ApplicationBar _Windows Phone 7 

 

  1. <!--LayoutRoot contains the root grid where all other page content is placed--> 
  2.     <Grid x:Name="LayoutRoot" Background="Transparent"> 
  3.         <Grid.RowDefinitions> 
  4.             <RowDefinition Height="Auto"/> 
  5.             <RowDefinition Height="*"/> 
  6.         </Grid.RowDefinitions> 
  7.  
  8.         <!--TitlePanel contains the name of the application and page title--> 
  9.         <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> 
  10.             <TextBlock x:Name="ApplicationTitle" Text="MOVIE PLAYER" Style="{StaticResource PhoneTextNormalStyle}"/> 
  11.         </StackPanel> 
  12.  
  13.         <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
  14.             <MediaElement Name="mediaElement"   
  15.                           Source="http://localhost/123.wmv" 
  16.                           AutoPlay="False" 
  17.                           MediaOpened="OnMediaElementMediaOpened" 
  18.                           MediaFailed="OnMediaElementMediaFailed" 
  19.                           CurrentStateChanged="OnMediaElementCurrentStateChanged"  /> 
  20.  
  21.             <TextBlock Name="statusText" 
  22.                        HorizontalAlignment="Left" 
  23.                        VerticalAlignment="Bottom" /> 
  24.  
  25.             <TextBlock Name="errorText" 
  26.                        HorizontalAlignment="Right" 
  27.                        VerticalAlignment="Bottom" 
  28.                        TextWrapping="Wrap" /> 
  29.         </Grid> 
  30.     </Grid> 
  31.  
  32.     <phone:PhoneApplicationPage.ApplicationBar> 
  33.         <shell:ApplicationBar> 
  34.             <shell:ApplicationBarIconButton   
  35.                     x:Name="appbarRewindButton" 
  36.                     IconUri="Images/appbar.transport.rew.rest.png"   
  37.                     Text="rewind" 
  38.                     IsEnabled="False" 
  39.                     Click="OnAppbarRewindClick" /> 
  40.  
  41.             <shell:ApplicationBarIconButton   
  42.                     x:Name="appbarPlayButton" 
  43.                     IconUri="Images/appbar.transport.play.rest.png"   
  44.                     Text="play" 
  45.                     IsEnabled="False" 
  46.                     Click="OnAppbarPlayClick" /> 
  47.  
  48.             <shell:ApplicationBarIconButton 
  49.                     x:Name="appbarPauseButton" 
  50.                     IconUri="Images/appbar.transport.pause.rest.png"   
  51.                     Text="pause" 
  52.                     IsEnabled="False" 
  53.                     Click="OnAppbarPauseClick" /> 
  54.  
  55.             <shell:ApplicationBarIconButton 
  56.                     x:Name="appbarEndButton" 
  57.                     IconUri="Images/appbar.transport.ff.rest.png"   
  58.                     Text="to end" 
  59.                     IsEnabled="False" 
  60.                     Click="OnAppbarEndClick" /> 
  61.         </shell:ApplicationBar> 
  62.     </phone:PhoneApplicationPage.ApplicationBar>