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

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

[源码下载]


与众不同 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

与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask
<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>
与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask

Launchers/ShareMediaTaskDemo.xaml.cs

与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask
/*
 * 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();
        }
    }
}
与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask


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

与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask
<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>
与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask

Launchers/SaveAppointmentTaskDemo.xaml.cs

与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask
/*
 * 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(1);
            saveAppointmentTask.EndTime = currentTime.AddHours(3);
            saveAppointmentTask.Subject = "喂孩子喝奶";
            saveAppointmentTask.Details = "放175的水,然后放4勺奶粉,冲调出200的奶";
            saveAppointmentTask.Location = "家里";
            saveAppointmentTask.IsAllDayEvent = false;
            saveAppointmentTask.Reminder = Reminder.FifteenMinutes; // 约会前 15 分钟显示提醒
            saveAppointmentTask.AppointmentStatus = AppointmentStatus.Busy; // 此约会期间将一直处于忙碌状态

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


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

与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask
<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>
与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask

Launchers/MapsTaskDemo.xaml.cs

与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask
/*
 * 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 = 7;  // 1 - zoomed out, 20 - zoomed in
            mapsTask.SearchTerm = "*";

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


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

与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask
<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>
与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask

Launchers/MapsDirectionsTaskDemo.xaml.cs

与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask
/*
 * 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();
        }
    }
}
与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask


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

与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask
<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>
与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask

Launchers/MapDownloaderTaskDemo.xaml.cs

与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask
/*
 * 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();
        }
    }
}
与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, 
SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask



OK
[源码下载]

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

上一篇:Android菜鸟的成长笔记(6)——剖析源码学自定义主题Theme


下一篇:SAP UI5 My Opportunity应用里的 currency validation