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

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

<!--LayoutRoot contains the root grid where all other page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MOVIE PLAYER" Style="{StaticResource PhoneTextNormalStyle}"/>
</StackPanel>

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<MediaElement Name="mediaElement"
Source="http://localhost/123.wmv"
AutoPlay="False"
MediaOpened="OnMediaElementMediaOpened"
MediaFailed="OnMediaElementMediaFailed"
CurrentStateChanged="OnMediaElementCurrentStateChanged" />

<TextBlock Name="statusText"
HorizontalAlignment="Left"
VerticalAlignment="Bottom" />

<TextBlock Name="errorText"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
TextWrapping="Wrap" />
</Grid>
</Grid>

<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar>
<shell:ApplicationBarIconButton
x:Name="appbarRewindButton"
IconUri="Images/appbar.transport.rew.rest.png"
Text="rewind"
IsEnabled="False"
Click="OnAppbarRewindClick" />

<shell:ApplicationBarIconButton
x:Name="appbarPlayButton"
IconUri="Images/appbar.transport.play.rest.png"
Text="play"
IsEnabled="False"
Click="OnAppbarPlayClick" />

<shell:ApplicationBarIconButton
x:Name="appbarPauseButton"
IconUri="Images/appbar.transport.pause.rest.png"
Text="pause"
IsEnabled="False"
Click="OnAppbarPauseClick" />

<shell:ApplicationBarIconButton
x:Name="appbarEndButton"
IconUri="Images/appbar.transport.ff.rest.png"
Text="to end"
IsEnabled="False"
Click="OnAppbarEndClick" />
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

View Code

using System;
using System.Windows;
using System.Windows.Media;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace MoviePlayer
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();

// Re-assign names already in the XAML file
appbarRewindButton = this.ApplicationBar.Buttons[0] as ApplicationBarIconButton;
appbarPlayButton = this.ApplicationBar.Buttons[1] as ApplicationBarIconButton;
appbarPauseButton = this.ApplicationBar.Buttons[2] as ApplicationBarIconButton;
appbarEndButton = this.ApplicationBar.Buttons[3] as ApplicationBarIconButton;
}

// ApplicationBar buttons
void OnAppbarRewindClick(object sender, EventArgs args)
{
mediaElement.Position = TimeSpan.Zero;
}

void OnAppbarPlayClick(object sender, EventArgs args)
{
mediaElement.Play();
}

void OnAppbarPauseClick(object sender, EventArgs args)
{
mediaElement.Pause();
}

void OnAppbarEndClick(object sender, EventArgs args)
{
mediaElement.Position = mediaElement.NaturalDuration.TimeSpan;
}

// MediaElement events
void OnMediaElementMediaFailed(object sender, ExceptionRoutedEventArgs args)
{
errorText.Text = args.ErrorException.Message;
}

void OnMediaElementMediaOpened(object sender, RoutedEventArgs args)
{
appbarRewindButton.IsEnabled = true;
appbarEndButton.IsEnabled = true;
}

void OnMediaElementCurrentStateChanged(object sender, RoutedEventArgs args)
{
statusText.Text = mediaElement.CurrentState.ToString();

if (mediaElement.CurrentState == MediaElementState.Stopped ||
mediaElement.CurrentState == MediaElementState.Paused)
{
appbarPlayButton.IsEnabled = true;
appbarPauseButton.IsEnabled = false;
}
else if (mediaElement.CurrentState == MediaElementState.Playing)
{
appbarPlayButton.IsEnabled = false;
appbarPauseButton.IsEnabled = true;
}
}
}
}

Windows Phone 7 程序菜单栏ApplicationBar相关推荐

  1. C#:如何用VS开启人生中第一个Windows窗体应用程序(Winform)?

    摘要:Windows窗体应用程序(Winform,下文以此指代)既能有效.直观地设计Windows窗体界面,又支持内部逻辑的编写.那么,对于C#初学者来说,如何开启第一个Winform程序呢? 编程语 ...

  2. C#学习教程12——Windows窗体应用程序

    文章目录 12.Windows窗体应用程序 12.1 创建Windows窗体应用程序 12.2 窗体属性 12.3 窗体事件 12.4 窗体方法 12.5 McssageBox:消息框 12.6 控件 ...

  3. Windows平台下程序打包流程

    Windows平台下程序打包流程 1.所有测试完成之后.程序release编译完成 2.依赖库打包 执行deploy.bat 脚本打包最新的程序以及依赖库 3.可执行程序打包 打开打包工程文件.evb ...

  4. Windows下Qt程序打包

    Windows下Qt程序打包 将windeployqt.exe 目录添加到系统环境变量 windeployqt.exe目录如下: 命令行打包 1.打开命令行 2.执行打包命令 windeployqt ...

  5. Windows Azure Platform Introduction (6) Windows Azure应用程序运行环境

    <Windows Azure Platform 系列文章目录> Windows Azure应用程序运行环境 Windows Azure云计算平台是提供PaaS(平台即服务)和IaaS(基础 ...

  6. Windows Phone 应用程序生命周期

    下图演示了 Windows Phone 应用程序的生命周期.在该图中,圆圈表示应用程序的状态.矩形显示应用程序应管理其状态的应用程序级别或页面级别的事件. Launching 事件 Launching ...

  7. 如何在C#Windows控制台应用程序中更新当前行?

    使用C#构建Windows控制台应用程序时,是否可以在不扩展当前行或转到新行的情况下写入控制台? 例如,如果我想显示一个百分比,该百分比代表一个过程到完成为止的距离,我只想在与光标相同的行上更新值,而 ...

  8. Windows Phone + VB 程序员=好的移动应用程序

    原文出处:http://blogs.msdn.com/b/somasegar/archive/2010/09/23/windows-phone-vb-developers-great-mobile-a ...

  9. 有了Windows Defender应用程序防护功能,再也不担心电脑免遭恶意***

    测试者发现,Windows 10 Creators Update (Redstone 2) build 15031中的Edge浏览器已经集成了Windows Defender应用程序防护功能,用户可以 ...

最新文章

  1. 金融货币衍生工具(结构性存款)
  2. 我喜爱的FireFox插件
  3. binlog工具_基于Binlog实时同步数仓,有哪些不为人知的坑?
  4. linux ubi 分区,Linux最新UBI文件系统介绍
  5. Android的BUG(四) - Android app的卡死问题
  6. c++基础day03
  7. pat 乙级 1032 挖掘机技术哪家强(C++)
  8. 利用indent格式化源文件的脚本
  9. python 常用代码
  10. Apache ab并发负载压力测试
  11. Intellij IDEA 系统路径配置
  12. queue emplace_c++ queue、deque、priority_queue/队列最大值/滑动窗口/top K
  13. 为什么下雨天容易犯困
  14. c++两个数组对比去掉重复的元素_每日一道 LeetCode (8):删除排序数组中的重复项和移除元素...
  15. hashmap扩容_聊一聊HashMap
  16. js上传图片转base64格式
  17. 超标量处理器设计 姚永斌 第6章 指令解码 摘录
  18. spring boot酒店会员点餐系统毕业设计源码072005
  19. 塔夫斯大学计算机教授,史上第一次生物创造,全球首个活体机器人诞生!
  20. postgreSQL 获取当前连接的IP

热门文章

  1. duilib入门简明教程 -- VS环境配置(2) (转)
  2. [MYSQL] 如何彻底卸载MYSQL5.x
  3. linkedlist(c语言_简单实现)
  4. QQ超市模拟排配2D版1.13 (XNA4.0) (修正双格货架移动的一个bug和3-5地图)
  5. 【解析】人人网:我的青春小鸟一样不回来
  6. 谈谈我对Spring IOC的理解
  7. Python多版本管理器-pyenv 介绍及部署记录
  8. set,env和export命令显示shell变量其区别,与环境变量扫盲(一)
  9. 纯JS实现带小圆点缩略图及左右箭头的轮播图
  10. CloudCC: 智能CRM究竟能否成为下一个行业风口?