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
繁體地址,請注明出處:http://hk.pswp.cn/news/379727.shtml
英文地址,請注明出處:http://en.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模塊的一…