• Windows Phone 7 程序菜单栏ApplicationBar


    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;
    }
    }
    }
    }
  • 相关阅读:
    Java工作中常用到的工具
    得到区块链直播记录
    如何高效的解决问题
    pgsql数据库应用两点注意
    flask如何使模板返回大文件,又不消耗大量内存
    python内存诊断
    pycharm整体缩进的快捷键
    gdb生成的core文件位置
    gdb源码安装,指定使用的python版本
    gdb源码安装过程中的问题:no termcap library found
  • 原文地址:https://www.cnblogs.com/linzheng/p/1957397.html
Copyright © 2020-2023  润新知