Microsoft.Phone.Shell命名空间中定义了ApplicationBar及其相关类(ApplicationBarIconButton和ApplicationBarMenuItem),这些类派生自Object,并完全独立于常规Silverlight编程中的DependencyObject,UIElement和FrameworkElement类层次结构。ApplicationBar最多能包含4个按钮,包含的图片通常是PNG文件,位图本身的宽高都是48像素,通常是透明的,实际图片应该是白色,在位图中间显示,是一个宽高均为26像素的正方形。

eg:
<phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Images/appbar.transport.rew.rest.png" Text="上一首"/>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar.transport.play.rest.png" Text="播放"/>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar.transport.pause.rest.png" Text="暂停"/>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar.transport.ff.rest.png" Text="下一首"/>
</shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>
这里非常重要的步骤是,需要将Images目录中的每一个位图文件的属性的Build Action 字段设置为Content,默认是Resource,如果是默认情况下,ApplicationBar无法智能地找到这些图像。
效果图:

当你点击省略号的时候,出现如下效果:

在这里,我们可以通过将ApplicationBarIconButton的IsEnabled属性设为false,从而禁用该按钮。

上面的2张图的第一个ApplicationBarIconButton的图片放错了。

一般情况下,我们要访问这些按钮可以如下做:

(this.ApplicationBar.Button[2] as ApplicationBarIconButton).IsEnabled=true or false

我们改造前面的demo来实现一个播放网络视频的案例来进一步的学习ApplicationBar的使用。

XAML文件:

<phone:PhoneApplicationPage
    x:Class="PhoneApp3.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

<!--LayoutRoot 是包含所有页面内容的根网格-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

<!--TitlePanel 包含应用程序的名称和页标题-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="电影播放" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="恐怖片" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

<!--ContentPanel - 在此处放置其他内容-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
         
            <MediaElement Name="mediaElement" Source="http://www.charlespetzold.com/Media/Walrus.wmv" AutoPlay="False" MediaOpened="onMediaElementOpened" MediaFailed="onMediaElementFailed" 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 IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Images/appbar.transport.rew.rest.png" Text="重置"    Click="onAppbarRewindClick" x:Name="appbarRewind" IsEnabled="False"/>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar.transport.play.rest.png" Text="播放" Click="onAppbarPlayClick" x:Name="appBarPlay" />
            <shell:ApplicationBarIconButton IconUri="/Images/appbar.transport.pause.rest.png" Text="暂停" Click="onAppbarPauseClick" x:Name="appBarPause" IsEnabled="False"/>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar.transport.ff.rest.png" Text="结束" Click="onAppbarEndClick" x:Name="appbarEnd" IsEnabled="False"/>

</shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

</phone:PhoneApplicationPage>

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace PhoneApp3
{
    public partial class MainPage : PhoneApplicationPage
    {
        // 构造函数
        public MainPage()
        {
            InitializeComponent();

appbarRewind = this.ApplicationBar.Buttons[0] as ApplicationBarIconButton;
            appBarPlay = this.ApplicationBar.Buttons[1] as ApplicationBarIconButton;
            appBarPause = this.ApplicationBar.Buttons[2] as ApplicationBarIconButton;
            appbarEnd = this.ApplicationBar.Buttons[3] as ApplicationBarIconButton;
        }

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;
        }

void onMediaElementFailed(object sender,ExceptionRoutedEventArgs args)
        {
            errorText.Text = args.ErrorException.Message;
        }

void onMediaElementOpened(object sender, RoutedEventArgs args)
        {
            appbarEnd.IsEnabled = true;
            appbarRewind.IsEnabled = true;
        }

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

if (mediaElement.CurrentState == MediaElementState.Stopped || mediaElement.CurrentState == MediaElementState.Paused)
            {
                appBarPlay.IsEnabled = true;
                appBarPause.IsEnabled = false;

}
            else if(mediaElement.CurrentState==MediaElementState.Playing)
            {
                appBarPause.IsEnabled = true;
                appBarPlay.IsEnabled = false;
            }

}
    
    }
}

Enjoy yourself.

转载于:https://www.cnblogs.com/yong2012/archive/2012/05/10/2493766.html

WP7之Application Bar控件相关推荐

  1. iOS开发UI篇—Date Picker和UITool Bar控件简单介绍

    iOS开发UI篇-Date Picker和UITool Bar控件简单介绍 一.Date Picker控件 1.简单介绍: Date Picker显示时间的控件 有默认宽高,不用设置数据源和代理 如何 ...

  2. MFC常见控件:滚动条控件

    MFC常见控件:滚动条控件 1. 滚动条控件简介 滚动条大家也很熟悉了,Windows窗口中很多都有滚动条.列表框和组合框设置了相应属性后,如果列表项显示不下也会出现滚动条.滚动条分为水平滚动条(Ho ...

  3. UWP开发随笔——UWP新控件!AutoSuggestBox!

    UWP开发随笔--UWP新控件!AutoSuggestBox! 原文:UWP开发随笔--UWP新控件!AutoSuggestBox! 摘要 要开发一款优秀的application,控件肯定是必不可少的 ...

  4. MFC入门基础(十二)控件 CScrollBar的使用

    1.参考博客: VS2010/MFC编程入门之二十六(常用控件:滚动条控件Scroll Bar)-软件开发-鸡啄米 以下内容是参考上述博客大神的稍作修改 2. 首先还是创建一个基于对话框的MFC工程 ...

  5. 自动注册activex控件

    编写Delphi应用程序时,经常会遇到一些ActiveX控件[注:扩展名为OCX的控件或DLL的类型库],它们为应用程序的开发提供了简单的操作途径.然而,这些程序在发布的同时,面临ActiveX控件注 ...

  6. OpenLayers-Editbar控件

    利用Editbar控件,可以在OpenLayers地图上绘制点.线.面图元. 1. 创建OpenLayers地图对象,并添加一个WMS图层作为底图. 2. 创建OpenLayers的Vector La ...

  7. CListCtrl控件详解

    1.视图类别 列表视图控件可用四种不同方式显示其内容,称之为"视图",有以下四个类别: 图标视图:每一项以全尺寸图标(32×32像素)出现,下面有一个标签.用户可在列表视图窗口拖动 ...

  8. JavaFX UI控件教程(十八)之Progress Bar和Progress Indicator

    翻译自  Progress Bar and Progress Indicator 在本章中,您将了解进度指示器和进度条,以及可视化JavaFX应用程序中任何操作进度的UI控件. 本ProgressIn ...

  9. JavaFX UI控件教程(十)之Scroll Bar

    翻译自   Scroll Bar 本章介绍如何使用滚动条控件创建可滚动窗格. 本ScrollBar类可以在应用程序中创建滚动窗格和意见.图9-1显示了滚动条的三个区域:拇指,右侧和左侧按钮(或向下和向 ...

最新文章

  1. CF1407D Discrete Centrifugal Jumps(单调队列+DP)
  2. qt中对任务繁忙时QProgressDialog的使用
  3. 中国城市人口分布区域分析
  4. maven编译项目时提示:cached in the local repository
  5. 实验1 熟悉实验环境
  6. 当设计模式遇上 Hooks
  7. 我更看好rust飞鸽传书
  8. FD.io VPP对 DPDK的详细配置:绑定网卡,启动VPP
  9. 惠斯通电桥信号调理芯片_基于精密分流电阻器的惠斯通电桥校准
  10. 字节跳动推出企业技术服务平台“火山引擎”
  11. linux中文输入法 ibus
  12. js 延迟几秒执行_息息相关的 JS 同步,异步和事件轮询
  13. 内存管理-内存slub分配器(二)
  14. ISO12233分辨率测试卡分类及功能说明
  15. 一步一步教你如何写开发文档
  16. 来一波PY交易吧(交换友链)
  17. android ipad 播放器,iPad 2高清视频播放器(AVPlayerHD)
  18. 多线程核心8-3:线程三大安全问题之发布与逸出
  19. win10系统要求配置_win10的配置要求是什么?对电脑硬件有什么要求?
  20. 工作流(Workflow)简介

热门文章

  1. Zend Debugger 配置
  2. [置顶] 状态压缩DP 简单入门题 11题
  3. [MOSS开发]:通过简单BUG跟踪Demo阐述用户控件对列表的操作
  4. 南邮计算机学院是211,南京邮电大学是211还是985
  5. java 在线编辑器_最好的Markdown开源在线编辑器,没有之一!
  6. 子集和问题 算法_子集问题 主要是去重算法
  7. java实现愤怒的小鸟游戏
  8. 前端工程师面经——概述及面试技巧加考点篇(一)
  9. 教你玩转CSS响应式设计
  10. 浏览器缓存原理以及本地存储