Windows Phone开发(26):启动器与选择器之五

移动开发
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox Live游戏、Xbox Music音乐与独特的视频体验整合至手机中。

启动器与选择器简单的地方在于,它们的使用方法几乎一模一样,从前面几节中,我相信大家基本上都知道如何使用它们了。
这里还是哆嗦一下吧,使用启动器和选择器的步骤如下:
1、实例化,new一个;
2、准备各参数,对相关的属性赋值;
3、Show;
4、对于启动器,不需要这步,但选择器有返回数据,所以需要处理完成事件。

本节再举两例子,启动器和选择器就可以完成了,然后我们下一节开始,探讨新的知识点。

例一:媒体播放器。

这是一个启动器,用起来更方便。
主要属性有:
Controls——要显示控制按钮,如暂集,停止等,它是一个带了Flags特性标记的枚举,所以可以多个值合并,如MediaPlaybackControls.Pause | MediaPlaybackControls.Stop

Location——要播放媒体的位置,Data表示文件存放在独立存储中,Install表示项目中的媒体文件;

Media——要播放文件的URI;

Orientation——这个更好懂了,媒体播放器的方向, 是水平还是垂直,和页面方向一个概念。

  1. <phone:PhoneApplicationPage    
  2.     x:Class="sampleApp.MainPage"   
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
  5.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"   
  6.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"   
  7.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"   
  8.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
  9.     mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"   
  10.     FontFamily="{StaticResource PhoneFontFamilyNormal}"   
  11.     FontSize="{StaticResource PhoneFontSizeNormal}"   
  12.     Foreground="{StaticResource PhoneForegroundBrush}"   
  13.     SupportedOrientations="Portrait" Orientation="Portrait"   
  14.     shell:SystemTray.IsVisible="True">   
  15.     <!--LayoutRoot 是包含所有页面内容的根网格-->   
  16.     <Grid x:Name="LayoutRoot" Background="Transparent">   
  17.         <Grid.RowDefinitions>   
  18.             <RowDefinition Height="Auto"/>   
  19.             <RowDefinition Height="*"/>   
  20.         </Grid.RowDefinitions>   
  21.         <!--TitlePanel 包含应用程序的名称和页标题-->   
  22.         <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">   
  23.             <TextBlock x:Name="ApplicationTitle" Text="我的应用程序" Style="{StaticResource PhoneTextNormalStyle}"/>   
  24.             <TextBlock x:Name="PageTitle" Text="页面名称" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>   
  25.         </StackPanel>   
  26.         <!--ContentPanel - 在此处放置其他内容-->   
  27.         <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">   
  28.             <Button Content="启动媒体播放器" Height="126" HorizontalAlignment="Left" Margin="31,116,0,0" Name="button1" VerticalAlignment="Top" Width="381" Click="button1_Click" />   
  29.         </Grid>   
  30.     </Grid>   
  31. </phone:PhoneApplicationPage>  
  1. using System;   
  2. using System.Collections.Generic;   
  3. using System.Linq;   
  4. using System.Net;   
  5. using System.Windows;   
  6. using System.Windows.Controls;   
  7. using System.Windows.Documents;   
  8. using System.Windows.Input;   
  9. using System.Windows.Media;   
  10. using System.Windows.Media.Animation;   
  11. using System.Windows.Shapes;   
  12. using Microsoft.Phone.Controls;   
  13. using Microsoft.Phone.Tasks;   
  14. namespace sampleApp   
  15. {   
  16.     public partial class MainPage : PhoneApplicationPage   
  17.     {   
  18.         // 构造函数   
  19.         public MainPage()   
  20.         {   
  21.             InitializeComponent();   
  22.         }   
  23.         private void button1_Click(object sender, RoutedEventArgs e)   
  24.         {   
  25.             MediaPlayerLauncher player = new MediaPlayerLauncher();   
  26.             player.Controls = MediaPlaybackControls.All;   
  27.             player.Location = MediaLocationType.Install;   
  28.             player.Media = new Uri("分飞燕.mp3", UriKind.Relative);   
  29.             player.Orientation = MediaPlayerOrientation.Portrait;   
  30.             player.Show();   
  31.         }   
  32.     }   
  33. }   

例二:搜索任务。

SearchTask类也是一个启动器,这个家伙更简单了,它只有一个属性要设置——SearchQuery,就是我们要搜索的关键字。

  1. <phone:PhoneApplicationPage    
  2.     x:Class="sampleApp.Page1"   
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
  5.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"   
  6.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"   
  7.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"   
  8.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
  9.     FontFamily="{StaticResource PhoneFontFamilyNormal}"   
  10.     FontSize="{StaticResource PhoneFontSizeNormal}"   
  11.     Foreground="{StaticResource PhoneForegroundBrush}"   
  12.     SupportedOrientations="Landscape" Orientation="Landscape"   
  13.     mc:Ignorable="d" d:DesignHeight="480" d:DesignWidth="728"   
  14.     shell:SystemTray.IsVisible="True">   
  15.     <!--LayoutRoot 是包含所有页面内容的根网格-->   
  16.     <Grid x:Name="LayoutRoot" Background="Transparent">   
  17.         <Grid.RowDefinitions>   
  18.             <RowDefinition Height="Auto"/>   
  19.             <RowDefinition Height="*"/>   
  20.         </Grid.RowDefinitions>   
  21.         <!--TitlePanel 包含应用程序的名称和页标题-->   
  22.         <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">   
  23.             <TextBlock x:Name="ApplicationTitle" Text="我的应用程序" Style="{StaticResource PhoneTextNormalStyle}"/>   
  24.             <TextBlock x:Name="PageTitle" Text="搜索" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>   
  25.         </StackPanel>   
  26.         <!--ContentPanel - 在此处放置其他内容-->   
  27.         <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">   
  28.             <TextBox Height="72" HorizontalAlignment="Left" Margin="12,86,0,0" Name="txtKey" VerticalAlignment="Top" Width="460" />   
  29.             <Button Content="搜索" Height="72" HorizontalAlignment="Left" Margin="480,86,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />   
  30.         </Grid>   
  31.     </Grid>   
  32. </phone:PhoneApplicationPage> 
  1. using System;   
  2. using System.Collections.Generic;   
  3. using System.Linq;   
  4. using System.Net;   
  5. using System.Windows;   
  6. using System.Windows.Controls;   
  7. using System.Windows.Documents;   
  8. using System.Windows.Input;   
  9. using System.Windows.Media;   
  10. using System.Windows.Media.Animation;   
  11. using System.Windows.Shapes;   
  12. using Microsoft.Phone.Controls;   
  13. using Microsoft.Phone.Tasks;   
  14. namespace sampleApp   
  15. {   
  16.     public partial class Page1 : PhoneApplicationPage   
  17.     {   
  18.         public Page1()   
  19.         {   
  20.             InitializeComponent();   
  21.         }   
  22.         private void button1_Click(object sender, RoutedEventArgs e)   
  23.         {   
  24.             SearchTask searcher = new SearchTask();   
  25.             searcher.SearchQuery = txtKey.Text;   
  26.             searcher.Show();   
  27.         }   
  28.     }   
  29. }  

下一节开始,我们讨论独立存储。

还有就是提一下建议,博客编辑器有问题,每次都这样,***次自动保存草稿后,后面就不会保存了,编辑器内的文本无法选定。而点击发表时没有反应,非得刷新页面。

责任编辑:闫佳明 来源: oschina
相关推荐

2013-04-18 13:56:09

Windows Pho启动器与选择器

2013-04-18 13:47:43

Windows Pho启动器与选择器发送短信

2013-04-18 11:13:04

Windows Pho启动器与选择器BingMapsDir

2013-04-18 13:28:19

Windows Pho启动器与选择器

2012-06-20 10:21:50

Windows Pho

2012-06-21 10:59:31

Windows Pho

2010-08-06 15:44:28

Windows PhoWindows PhoSilverlight

2010-04-12 17:32:59

Windows Pho

2011-10-19 09:56:58

Gnome Pie程序启动器

2012-04-16 14:32:31

iOS选择器代码

2010-09-02 11:26:33

CSS选择器伪类

2011-11-28 13:42:55

Sencha Touc组件选择器

2012-12-27 14:08:39

Android开发颜色选择器

2017-03-20 14:46:07

Android日期时间选择器

2013-07-31 13:13:50

Windows PhoMVVM模式

2009-06-30 13:58:00

Java启动器

2012-11-09 14:33:38

WindowsChrome

2012-04-19 08:42:22

春Phone沙龙

2014-08-12 09:54:05

Android定制化启动器

2009-07-16 11:02:33

Swing文件选择器
点赞
收藏

51CTO技术栈公众号