WP7之Application Bar控件

  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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.pswp.cn/news/379727.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

TomCat使用以及端口号被占用的处理方法

一.HTTP协议 什么是HTTP协议 HTTP协议&#xff08;HyperText Transfer Protocol&#xff0c;超文本传输协议&#xff09;是因特网上应用最为广泛的一种网络传输协议&#xff0c;所有的WWW文件都必须遵守这个标准。 HTTP请求 HTTP响应 2.如何处理端口被占用 方法一&#xff…

FreeRTOS事件标志组

使用信号量来同步的话&#xff0c;任务只能与单个事务或任务进行同步&#xff0c;有时候某个任务可能会需要与多个事件或任务进行同步&#xff0c;此时信号量就无能为力了&#xff0c;FreeRTOS为此提供了一个可选的解决方法&#xff0c;那就是事件标志组。 0x01 事件标志组 事…

FusionCharts等产品简介

以前做柱状图、饼形图等图表都是根据数据绘制出来的静态图&#xff0c;偶然看到别人的一套系统&#xff0c;居然可以让柱状图的柱子动画般的逐个出现&#xff0c;效果还是很不错的。不要跟我抬杠说不就是展现数据嘛&#xff0c;静态图表有什么不好&#xff0c;要知道用户一般可…

c#foreach循环_C#| 使用foreach循环打印整数数组

c#foreach循环Given an integer array and we have to print its elements using "foreach loop" in C#. 给定一个整数数组&#xff0c;我们必须在C&#xff03;中使用“ foreach循环”打印其元素 。 Syntax for foreach loop: foreach循环的语法&#xff1a; fore…

Eclipse和Tomcat绑定并且将上传资源到Tomcat上

步骤如下&#xff1a; 创建一个Dynamic Web Project&#xff08;图一&#xff09; Target runtime 选择Apache Tomcat v7.0版本&#xff08;图二&#xff09; 切记要选择 v7.0 和2.5 &#xff08;若没有图二选项见图三&#xff09; 然后&#xff0c;点击window --> Prefer…

浅析.NET平台编程语言的未来走向

在去年的PDC2008召开期间&#xff0c;微软逐步公开了围绕.NET和编程语言的很多想法&#xff0c;据此我们可以饶有兴趣地对.NET的未来预测一番。 .NET平台以运行在通用语言运行时(Common Language Runtime&#xff0c;CLR)上的C#和VB.NET作为开端。CLR是通用语言架构(Common Lan…

FreeRTOS任务通知

从v8.2.0版本开始&#xff0c;FreeRTOS新增了任务通知这个功能&#xff0c;可以使用任务通知来代替信号量、消息队列、事件标志组等这些东西&#xff0c;使用任务通知的话效率会更高。 任务通知在FreeRTOS是一个可选的选项&#xff0c;要使用任务通知的话就需要将宏configUSE_T…

kinect在openni下也能玩抠出人物换背景

之前想了个很拉风的名字《用kinect玩穿越》&#xff0c;但是现在功能还不是很完善&#xff0c;细节处理也不是很好&#xff0c;脸皮没有足够的厚&#xff0c;所以呢还是叫换背景吧。 这里面包含两个技术要点&#xff1a; 一、抠出活动人物 在微软的SDK里深度图像的前3位即0-2位…

物联网基础知识_联网| 基础知识能力问答 套装1

物联网基础知识1) There are the following statements that are given below, which of them are correct about the computer network? A computer network is an interconnection between multiple devices to share hardware resources and information.A computer networ…

Emit学习-基础篇-基本概念介绍

之前的Hello World例子应该已经让我们对Emit有了一个模糊的了解&#xff0c;那么Emit到底是什么样一个东西&#xff0c;他又能实现些什么功能呢&#xff1f;昨天查了点资料&#xff0c;大致总结了下&#xff0c;由于才开始学习肯定有不完善的地方&#xff0c;希望大家能够批评指…

The FreeRTOS Distribution(介绍、移植、类型定义)

1 Understand the FreeRTOS Distribution 1.1 Definition &#xff1a;FreeRTOS Port FreeRTOS目前可以在20种不同的编译器构建&#xff0c;并且可以在30多种不同的处理器架构上运行&#xff0c;每个受支持的编译器和处理器组合被认为是一个单独的FreeRTOS Port。 1.2 Build…

notepad++节点_在C ++中删除链接列表的中间节点

notepad节点Given a single Linked List and we have to delete the middle the element of the Linked List. 给定一个链表&#xff0c;我们必须删除链表中间的元素。 If the length of the linked list is odd then delete (( n1)/2)th term of the linked list and if the…

SET ANSI_NULLS ON

指定在与 Null 值一起使用等于 () 和不等于 (<>) 比较运算符时采用符合 ISO 标准的行为。 当 SET ANSI_NULLS 为 ON 时&#xff0c;即使 column_name 中包含空值&#xff0c;使用 WHERE column_name NULL 的 SELECT 语句仍返回零行。即使 column_name 中包含非空值&…

Eclipse项目左上角出现大红色感叹号怎么办?

出现大红色感叹号是因为环境不匹配 解决方法&#xff1a; 右击出现大红色感叹号的项目 点击 Libraries&#xff0c;将有叉号的给Remove掉 然后再点击 Add Library —> JRE System Library —> Next 勾选第二个即可 之后&#xff0c;就不会出现大红色感叹号了。

PCB---STM32最小系统制作过程

PCB 制作过程STM32核心模块连接外部电源晶振OSC_IN(8MHz)OSC32_IN(32.768MHz&#xff09;复位下载口BOOT模式电源模块添加功能UARTWKUPSTM32核心模块 这里我们以STM32F103C8T6为列&#xff0c;先将芯片的原理图放到原理图中 对于STM32&#xff0c;有几个模块是核心&#xff0…

scala 随机生成整数_如何在Scala中以整数形式获取当前年份?

scala 随机生成整数In Scala programming language, there is an option for the programmer to use libraries of java because of its interoperability with java. 在Scala编程语言中&#xff0c;程序员可以选择使用Java库&#xff0c;因为它可以与Java互操作。 There are …

转载:glut.h 与 stdlib.h中 的exit()重定义问题的解决

遇到的问题&#xff0c;来自&#xff1a;http://blog.sina.com.cn/s/blog_629c53bd0100f5li.html 出现&#xff1a; c:\codeprogram\microsoft visual studio 10.0\vc\include\stdlib.h(353): error C2381: “exit”: 重定义&#xff1b;__declspec(noreturn) 不同1> c:\pro…

括号配对问题(C++栈)

题目描述: 现在&#xff0c;有一行括号序列&#xff0c;请你检查这行括号是否配对。 输入描述: 第一行输入一个数N&#xff08;0<N<100&#xff09;,表示有N组测试数据。后面的N行输入多组输入数据&#xff0c;每组输入数据都是一个字符串S(S的长度小于10000&#xff0c;…

FreeRTOS---堆内存管理(一)

FreeRTOS的堆内存管理简介动态内存分配及其与 FreeRTOS 的相关性动态内存分配选项内存分配方案Heap_1heap_2Heap_3Heap_4设置heap_4的起始地址Heap_5vPortDefineHeapRegions()堆相关的函数xPortGetFreeHeapSizexPortGetMinimumEverFreeHeapSizeMalloc调用失败的Hook函数这篇文章…

python中生成随机整数_在Python中生成0到9之间的随机整数

python中生成随机整数Following are the few explanatory illustrations using different python modules, on how to generate random integers? Consider the scenario of generating the random numbers between 0 and 9 (both inclusive). 以下是使用不同的python模块的一…