与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask

时间:2021-11-17 14:14:12

[源码下载]

与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask

作者:webabcd

介绍
与众不同 windows phone 8.0 之 新的启动器

  • ShareMediaTask - 共享媒体文件
  • ShareMediaTask - 新建“约会”到“日历”
  • MapsTask - Nokia 地图
  • MapsDirectionsTask - Nokia 地图行车路线
  • MapDownloaderTask - 管理 Nokia 离线地图

示例
1、演示 ShareMediaTask - 共享媒体文件
Launchers/ShareMediaTaskDemo.xaml

<phone:PhoneApplicationPage
x:Class="Demo.Launchers.ShareMediaTaskDemo"
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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True"> <StackPanel>
<TextBlock Name="lblMsg" TextWrapping="Wrap" /> <Button Name="btnDemo" Content="Demo" Click="btnDemo_Click" />
</StackPanel> </phone:PhoneApplicationPage>

Launchers/ShareMediaTaskDemo.xaml.cs

/*
* ShareMediaTask - 共享媒体文件
* FilePath - 需要共享的媒体文件的地址
* Show() - 弹出共享对话框(包含很多 provider,选择一个以共享媒体文件)
*/ using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks; namespace Demo.Launchers
{
public partial class ShareMediaTaskDemo : PhoneApplicationPage
{
public ShareMediaTaskDemo()
{
InitializeComponent();
} private void btnDemo_Click(object sender, RoutedEventArgs e)
{
// 选择一个图片
PhotoChooserTask photoChooserTask = new PhotoChooserTask();
photoChooserTask.ShowCamera = true;
photoChooserTask.Completed += photoChooserTask_Completed;
photoChooserTask.Show();
} void photoChooserTask_Completed(object sender, PhotoResult e)
{
lblMsg.Text = "文件地址:" + e.OriginalFileName; // 弹出共享对话框,从中选择一个 provider 以共享媒体文件
ShareMediaTask shareMediaTask = new ShareMediaTask();
shareMediaTask.FilePath = e.OriginalFileName;
shareMediaTask.Show();
}
}
}

2、演示 SaveAppointmentTask - 新建“约会”到“日历”
Launchers/SaveAppointmentTaskDemo.xaml

<phone:PhoneApplicationPage
x:Class="Demo.Launchers.SaveAppointmentTaskDemo"
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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True"> <StackPanel>
<Button Name="btnDemo" Content="Demo" Click="btnDemo_Click" />
</StackPanel> </phone:PhoneApplicationPage>

Launchers/SaveAppointmentTaskDemo.xaml.cs

/*
* SaveAppointmentTask - 新建“约会”到“日历”
* StartTime - 约会的开始时间
* EndTime - 约会的结束时间
* Subject - 主题
* Details - 详细信息
* Location - 地点
* IsAllDayEvent - 是否是全天事件
* Reminder - 约会的提醒时间(Microsoft.Phone.Tasks.Reminder 枚举)
* AppointmentStatus - 约会的状态(Microsoft.Phone.UserData.AppointmentStatus 枚举)
* Show() - 弹出日历程序,并预填上指定的信息
*/ using System;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using Microsoft.Phone.UserData; namespace Demo.Launchers
{
public partial class SaveAppointmentTaskDemo : PhoneApplicationPage
{
public SaveAppointmentTaskDemo()
{
InitializeComponent();
} private void btnDemo_Click(object sender, RoutedEventArgs e)
{
DateTime currentTime = DateTime.Now; SaveAppointmentTask saveAppointmentTask = new SaveAppointmentTask(); saveAppointmentTask.StartTime = currentTime.AddHours();
saveAppointmentTask.EndTime = currentTime.AddHours();
saveAppointmentTask.Subject = "喂孩子喝奶";
saveAppointmentTask.Details = "放175的水,然后放4勺奶粉,冲调出200的奶";
saveAppointmentTask.Location = "家里";
saveAppointmentTask.IsAllDayEvent = false;
saveAppointmentTask.Reminder = Reminder.FifteenMinutes; // 约会前 15 分钟显示提醒
saveAppointmentTask.AppointmentStatus = AppointmentStatus.Busy; // 此约会期间将一直处于忙碌状态 saveAppointmentTask.Show();
}
}
}

3、演示 MapsTask - Nokia 地图
Launchers/MapsTaskDemo.xaml

<phone:PhoneApplicationPage
x:Class="Demo.Launchers.MapsTaskDemo"
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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True"> <StackPanel>
<Button Name="btnDemo" Content="Demo" Click="btnDemo_Click" />
</StackPanel> </phone:PhoneApplicationPage>

Launchers/MapsTaskDemo.xaml.cs

/*
* MapsTask - Nokia 地图
* SearchTerm - 需要在地图中搜索的内容
* Center - 地图中心点的坐标
* ZoomLevel - 地图的放大级别
* Show() - 按指定要求打开 Nokia 地图
*/ using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using System.Device.Location; namespace Demo.Launchers
{
public partial class MapsTaskDemo : PhoneApplicationPage
{
public MapsTaskDemo()
{
InitializeComponent();
} private void btnDemo_Click(object sender, RoutedEventArgs e)
{
MapsTask mapsTask = new MapsTask(); mapsTask.Center = new GeoCoordinate(39.9, 116.3); // 北京
mapsTask.ZoomLevel = ; // 1 - zoomed out, 20 - zoomed in
mapsTask.SearchTerm = "*"; mapsTask.Show();
}
}
}

4、演示 MapsDirectionsTask - Nokia 地图行车路线
Launchers/MapsDirectionsTaskDemo.xaml

<phone:PhoneApplicationPage
x:Class="Demo.Launchers.MapsDirectionsTaskDemo"
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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True"> <StackPanel>
<Button Name="btnDemo" Content="Demo" Click="btnDemo_Click" />
</StackPanel> </phone:PhoneApplicationPage>

Launchers/MapsDirectionsTaskDemo.xaml.cs

/*
* MapsDirectionsTask - Nokia 地图行车路线
* Start - 行车路线的开始位置(LabeledMapLocation 类型)
* End - 行车路线的结束位置(LabeledMapLocation 类型)
* Show() - 打开 Nokia 地图,并显示指定开始位置和结束位置的行车路线
*
* LabeledMapLocation - 关联了标签的地理坐标
* Label - 位置的文本标签
* Location - 位置的地理坐标
*/ using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using System.Device.Location; namespace Demo.Launchers
{
public partial class MapsDirectionsTaskDemo : PhoneApplicationPage
{
public MapsDirectionsTaskDemo()
{
InitializeComponent();
} private void btnDemo_Click(object sender, RoutedEventArgs e)
{
MapsDirectionsTask mapsDirectionsTask = new MapsDirectionsTask(); // 如果不指定地理坐标,则会针对位置标签进行搜索
LabeledMapLocation lml = new LabeledMapLocation("*", null);
mapsDirectionsTask.End = lml; // Start 和 End 必须至少指定其中之一,当只指定一个时,另一个则使用本地位置
mapsDirectionsTask.Show();
}
}
}

5、演示 MapDownloaderTask - 管理 Nokia 离线地图
Launchers/MapDownloaderTaskDemo.xaml

<phone:PhoneApplicationPage
x:Class="Demo.Launchers.MapDownloaderTaskDemo"
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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True"> <StackPanel>
<Button Name="btnDemo" Content="Demo" Click="btnDemo_Click" />
</StackPanel> </phone:PhoneApplicationPage>

Launchers/MapDownloaderTaskDemo.xaml.cs

/*
* MapDownloaderTask - 管理 Nokia 离线地图
* Show() - 弹出 Nokia 离线地图管理窗口
*/ using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks; namespace Demo.Launchers
{
public partial class MapDownloaderTaskDemo : PhoneApplicationPage
{
public MapDownloaderTaskDemo()
{
InitializeComponent();
} private void btnDemo_Click(object sender, RoutedEventArgs e)
{
MapDownloaderTask mapDownloaderTask = new MapDownloaderTask(); mapDownloaderTask.Show();
}
}
}

OK
[源码下载]