与众不同 windows phone (5) - Chooser(选择器)

简介: 原文:与众不同 windows phone (5) - Chooser(选择器)[索引页][源码下载] 与众不同 windows phone (5) - Chooser(选择器) 作者:webabcd介绍与众不同 windows phone 7.
原文: 与众不同 windows phone (5) - Chooser(选择器)

[索引页]
[源码下载]


与众不同 windows phone (5) - Chooser(选择器)



作者:webabcd


介绍
与众不同 windows phone 7.5 (sdk 7.1) 之选择

  • AddressChooserTask - 选择联系人的地址
  • EmailAddressChooserTask - 选择联系人的email
  • PhoneNumberChooserTask - 选择联系人的电话
  • SaveContactTask - 保存联系方式
  • SaveEmailAddressTask - 保存电子邮件地址
  • SavePhoneNumberTask - 保存电话号码
  • SaveRingtoneTask - 保存铃声
  • PhotoChooserTask - 从图库里选择照片
  • CameraCaptureTask - 相机拍照
  • GameInviteTask - 游戏邀请(邀请其他人加入我的游戏会话)



示例
1、AddressChooserTask 的 Demo
AddressChooserTask.xaml.cs

/*
 * AddressChooserTask - 选择联系人的地址
 *     Completed - 选中地址之后所执行的事件
 *     Show() - 显示联系人列表
 * 
 * TaskResult - 用户选择后的结果
 *     OK - 成功
 *     Cancel - 取消
 *     None - 失败
 *     
 * AddressResult - Completed 事件的事件参数
 *     DisplayName - 联系人名称
 *     Address - 联系人的地址
 */

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.Tasks;

namespace Demo.Choosers
{
    public partial class AddressChooserTaskDemo : PhoneApplicationPage
    {
        private AddressChooserTask _addressChooserTask;

        public AddressChooserTaskDemo()
        {
            InitializeComponent();
        }

        private void btnDemo_Click(object sender, RoutedEventArgs e)
        {
            _addressChooserTask = new AddressChooserTask();
            _addressChooserTask.Completed += new EventHandler<AddressResult>(_addressChooserTask_Completed);

            try
            {
                _addressChooserTask.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        void _addressChooserTask_Completed(object sender, AddressResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                MessageBox.Show("" + e.DisplayName + "”的地址是:" + e.Address);
            }
        }
    }
}

 

2、EmailAddressChooserTask 的 Demo
EmailAddressChooserTask.xaml.cs

/*
 * EmailAddressChooserTask - 选择联系人的email
 *     Completed - 选中email之后所执行的事件
 *     Show() - 显示联系人列表
 *     
 * TaskResult - 用户选择后的结果
 *     OK - 成功
 *     Cancel - 取消
 *     None - 失败
 *     
 * EmailResult - Completed 事件的事件参数
 *     DisplayName - 联系人名称
 *     Email - 联系人的email
 */

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.Tasks;

namespace Demo.Choosers
{
    public partial class EmailAddressChooserTaskDemo : PhoneApplicationPage
    {
        private EmailAddressChooserTask _emailAddressChooserTask;

        public EmailAddressChooserTaskDemo()
        {
            InitializeComponent();
        }

        private void btnDemo_Click(object sender, RoutedEventArgs e)
        {
            _emailAddressChooserTask = new EmailAddressChooserTask();
            _emailAddressChooserTask.Completed += new EventHandler<EmailResult>(_emailAddressChooserTask_Completed);

            try
            {
                _emailAddressChooserTask.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        void _emailAddressChooserTask_Completed(object sender, EmailResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                MessageBox.Show("" + e.DisplayName + "”的email是:" + e.Email);
            }
        }
    }
}

 

3、PhoneNumberChooserTask 的 Demo
PhoneNumberChooserTask.xaml.cs

/*
 * PhoneNumberChooserTask - 选择联系人的电话
 *     Completed - 选中电话之后所执行的事件
 *     Show() - 显示联系人列表
 *     
 * TaskResult - 用户选择后的结果
 *     OK - 成功
 *     Cancel - 取消
 *     None - 失败
 *     
 * PhoneNumberResult - Completed 事件的事件参数
 *     DisplayName - 联系人名称
 *     PhoneNumber - 联系人的电话
 */

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.Tasks;

namespace Demo.Choosers
{
    public partial class PhoneNumberChooserTaskDemo : PhoneApplicationPage
    {
        private PhoneNumberChooserTask _phoneNumberChooserTask;

        public PhoneNumberChooserTaskDemo()
        {
            InitializeComponent();
        }

        private void btnDemo_Click(object sender, RoutedEventArgs e)
        {
            _phoneNumberChooserTask = new PhoneNumberChooserTask();
            _phoneNumberChooserTask.Completed += new EventHandler<PhoneNumberResult>(_phoneNumberChooserTask_Completed);

            try
            {
                _phoneNumberChooserTask.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        void _phoneNumberChooserTask_Completed(object sender, PhoneNumberResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                MessageBox.Show("" + e.DisplayName + "”的电话号码是:" + e.PhoneNumber);
            }
        }
    }
}

 

4、SaveContactTask 的 Demo
SaveContactTask.xaml.cs

/*
 * SaveContactTask - 保存联系方式
 *     Completed - 完成保存操作(成功、取消、失败)之后所执行的事件
 *     FirstName, MiddleName, LastName, Nickname, HomeAddressCity, HomeAddressCountry, HomeAddressState, HomeAddressStreet, HomeAddressZipCode, HomePhone, WorkAddressCity, WorkAddressCountry, WorkAddressState, WorkAddressStreet, WorkAddressZipCode, WorkEmail, WorkPhone, Suffix, Title, Website, JobTitle, Company, MobilePhone, PersonalEmail, OtherEmail, Notes
 *     Show() - 显示用于保存联系方式的窗口
 * 
 * TaskResult - 任务结果
 *     OK - 成功
 *     Cancel - 取消
 *     None - 失败
 */

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.Tasks;

namespace Demo.Choosers
{
    public partial class SaveContactTaskDemo : PhoneApplicationPage
    {
        private SaveContactTask _saveContactTask;

        public SaveContactTaskDemo()
        {
            InitializeComponent();
        }

        private void btnDemo_Click(object sender, RoutedEventArgs e)
        {
            _saveContactTask = new SaveContactTask();
            _saveContactTask.Completed += new EventHandler<SaveContactResult>(_saveContactTask_Completed);

            try
            {
                _saveContactTask.FirstName = "web";
                _saveContactTask.LastName = "abcd";
                _saveContactTask.MobilePhone = "11111111111";

                _saveContactTask.Show();
            }
            catch (System.InvalidOperationException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        void _saveContactTask_Completed(object sender, SaveContactResult e)
        {
            switch (e.TaskResult)
            {
                case TaskResult.OK:
                    MessageBox.Show("保存成功");
                    break;

                case TaskResult.Cancel:
                    MessageBox.Show("取消保存");
                    break;

                case TaskResult.None:
                    MessageBox.Show("无法保存");
                    break;
            }
        }
    }
}

 

5、SaveEmailAddressTask 的 Demo
SaveEmailAddressTask.xaml.cs

/*
 * SaveEmailAddressTask - 保存电子邮件地址
 *     Completed - 完成保存操作(成功、取消、失败)之后所执行的事件
 *     Email - 需要保存的电子邮件地址
 *     Show() - 显示用于保存电子邮件地址的窗口
 * 
 * TaskResult - 任务结果
 *     OK - 成功
 *     Cancel - 取消
 *     None - 失败
 */

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.Tasks;

namespace Demo.Choosers
{
    public partial class SaveEmailAddressTaskDemo : PhoneApplicationPage
    {
        private SaveEmailAddressTask _saveEmailAddressTask;

        public SaveEmailAddressTaskDemo()
        {
            InitializeComponent();
        }

        private void btnDemo_Click(object sender, RoutedEventArgs e)
        {
            _saveEmailAddressTask = new SaveEmailAddressTask();
            _saveEmailAddressTask.Completed += new EventHandler<TaskEventArgs>(_saveEmailAddressTask_Completed);

            try
            {
                _saveEmailAddressTask.Email = "a@b.c";

                _saveEmailAddressTask.Show();
            }
            catch (System.InvalidOperationException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        void _saveEmailAddressTask_Completed(object sender, TaskEventArgs e)
        {
            switch (e.TaskResult)
            {
                case TaskResult.OK:
                    MessageBox.Show("保存成功");
                    break;

                case TaskResult.Cancel:
                    MessageBox.Show("取消保存");
                    break;

                case TaskResult.None:
                    MessageBox.Show("无法保存");
                    break;
            }
        }
    }
}

 

6、SavePhoneNumberTask 的 Demo
SavePhoneNumberTask.xaml.cs

/*
 * SavePhoneNumberTask - 保存电话号码
 *     Completed - 完成保存操作(成功、取消、失败)之后所执行的事件
 *     PhoneNumber - 需要保存的电话号码
 *     Show() - 显示用于保存电话号码的窗口
 * 
 * TaskResult - 任务结果
 *     OK - 成功
 *     Cancel - 取消
 *     None - 失败
 */

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.Tasks;

namespace Demo.Choosers
{
    public partial class SavePhoneNumberTaskDemo : PhoneApplicationPage
    {
        private SavePhoneNumberTask _savePhoneNumberTask;

        public SavePhoneNumberTaskDemo()
        {
            InitializeComponent();
        }

        private void btnDemo_Click(object sender, RoutedEventArgs e)
        {
            _savePhoneNumberTask = new SavePhoneNumberTask();
            _savePhoneNumberTask.Completed += new EventHandler<TaskEventArgs>(_savePhoneNumberTask_Completed);

            try
            {
                _savePhoneNumberTask.PhoneNumber = "11111111111";

                _savePhoneNumberTask.Show();
            }
            catch (System.InvalidOperationException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        void _savePhoneNumberTask_Completed(object sender, TaskEventArgs e)
        {
            switch (e.TaskResult)
            {
                case TaskResult.OK:
                    MessageBox.Show("保存成功");
                    break;

                case TaskResult.Cancel:
                    MessageBox.Show("取消保存");
                    break;

                case TaskResult.None:
                    MessageBox.Show("无法保存");
                    break;
            }
        }
    }
}

 

7、SaveRingtoneTask 的 Demo
SaveRingtoneTask.xaml.cs

/*
 * SaveRingtoneTask - 保存铃声
 *     Completed - 保存铃声之后所执行的事件
 *     Source - 铃声文件的地址
 *     IsShareable - 指示该铃声是否可被其他应用程序访问
 *     DisplayName - 铃声的名称(显示用)
 *     Show() - 显示保存铃声窗口
 * 
 * TaskResult - 任务结果
 *     OK - 成功
 *     Cancel - 取消
 *     None - 失败
 */

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.Tasks;

namespace Demo.Choosers
{
    public partial class SaveRingtoneTaskDemo : PhoneApplicationPage
    {
        private SaveRingtoneTask _saveRingtoneChooser;

        public SaveRingtoneTaskDemo()
        {
            InitializeComponent();
        }

        private void btnDemo_Click(object sender, RoutedEventArgs e)
        {
            _saveRingtoneChooser = new SaveRingtoneTask();
            _saveRingtoneChooser.Completed += new EventHandler<TaskEventArgs>(_saveRingtoneChooser_Completed);

            try
            {
                _saveRingtoneChooser.Source = new Uri("appdata:/Assets/SuperMario.mp3"); // appdata: 代表程序包内
                // saveRingtoneChooser.Source = new Uri("isostore:/myTone.mp3"); // isostore: 代表独立存储
                // _saveRingtoneChooser.Source = new Uri("http://a.b.c/d.mp3"); // 网络地址
                _saveRingtoneChooser.IsShareable = true;

                _saveRingtoneChooser.DisplayName = "超级马里奥铃声";

                _saveRingtoneChooser.Show();
            }
            catch (System.InvalidOperationException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        void _saveRingtoneChooser_Completed(object sender, TaskEventArgs e)
        {
            switch (e.TaskResult)
            {
                case TaskResult.OK:
                    MessageBox.Show("保存成功");
                    break;

                case TaskResult.Cancel:
                    MessageBox.Show("取消保存");
                    break;

                case TaskResult.None:
                    MessageBox.Show("无法保存");
                    break;
            }
        }
    }
}

 

8、PhotoChooserTask 的 Demo
PhotoChooserTask.xaml.cs

/*
 * PhotoChooserTask - 从图库里选择照片
 *     Completed - 选中照片之后所执行的事件
 *     Show() - 显示图库
 * 
 * TaskResult - 任务结果
 *     OK - 成功
 *     Cancel - 取消
 *     None - 失败
 *     
 * PhotoResult - Completed 事件的事件参数
 *     ChosenPhoto - 照片数据(System.IO.Stream 类型)
 *     OriginalFileName - 照片的文件名
 */

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.Tasks;

namespace Demo.Choosers
{
    public partial class PhotoChooserTaskDemo : PhoneApplicationPage
    {
        private PhotoChooserTask _photoChooserTask;

        public PhotoChooserTaskDemo()
        {
            InitializeComponent();
        }

        private void btnDemo_Click(object sender, RoutedEventArgs e)
        {
            _photoChooserTask = new PhotoChooserTask();
            _photoChooserTask.Completed += new EventHandler<PhotoResult>(_photoChooserTask_Completed);

            try
            {
                _photoChooserTask.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        void _photoChooserTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                bmp.SetSource(e.ChosenPhoto);
                img.Source = bmp;
            }
        }
    }
}

 

9、CameraCaptureTask 的 Demo
CameraCaptureTask.xaml.cs

/*
 * CameraCaptureTask - 相机拍照
 *     Completed - 拍照并确认之后所执行的事件
 *     Show() - 启动相机
 * 
 * TaskResult - 任务结果
 *     OK - 成功
 *     Cancel - 取消
 *     None - 失败
 *     
 * PhotoResult - Completed 事件的事件参数
 *     ChosenPhoto - 照片数据(System.IO.Stream 类型)
 *     OriginalFileName - 照片的文件名
 */

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.Tasks;

namespace Demo.Choosers
{
    public partial class CameraCaptureTaskDemo : PhoneApplicationPage
    {
        private CameraCaptureTask _cameraCaptureTask;

        public CameraCaptureTaskDemo()
        {
            InitializeComponent();
        }

        private void btnDemo_Click(object sender, RoutedEventArgs e)
        {
            _cameraCaptureTask = new CameraCaptureTask();
            _cameraCaptureTask.Completed += new EventHandler<PhotoResult>(_cameraCaptureTask_Completed);

            try
            {
                _cameraCaptureTask.Show();
            }
            catch (System.InvalidOperationException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        void _cameraCaptureTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                bmp.SetSource(e.ChosenPhoto);
                img.Source = bmp;
            }
        }
    }
}

 

10、GameInviteTask 的 Demo
GameInviteTask.xaml.cs

/*
 * GameInviteTask - 游戏邀请(邀请其他人加入我的游戏会话)
 *     Completed - 完成操作之后所执行的事件
 *     SessionId - 游戏的会话 ID
 *     Show() - 发出邀请
 *     
 * TaskResult - 用户选择后的结果
 *     OK - 成功
 *     Cancel - 取消
 *     None - 失败
 */

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.Tasks;

namespace Demo.Choosers
{
    public partial class GameInviteTaskDemo : PhoneApplicationPage
    {
        private GameInviteTask _gameInviteTask;

        public GameInviteTaskDemo()
        {
            InitializeComponent();
        }

        private void btnDemo_Click(object sender, RoutedEventArgs e)
        {
            _gameInviteTask = new GameInviteTask();
            _gameInviteTask.Completed += new EventHandler<TaskEventArgs>(_gameInviteTask_Completed);

            try
            {
                // 游戏需要在 Windows Phone 上的 Xbox LIVE 中发布,并且邀请人也要是 Xbox LIVE 的会员
                _gameInviteTask.SessionId = "游戏的 session id";
                _gameInviteTask.Show();
            }
            catch (System.InvalidOperationException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        void _gameInviteTask_Completed(object sender, TaskEventArgs e)
        {
            switch (e.TaskResult)
            {
                case TaskResult.OK:
                    MessageBox.Show("游戏邀请已发送");
                    break;

                case TaskResult.Cancel:
                    MessageBox.Show("游戏邀请已取消");
                    break;

                case TaskResult.None:
                    MessageBox.Show("游戏邀请无法发送");
                    break;
            }
        }
    }
}



OK
[源码下载]

目录
相关文章
|
Android开发 iOS开发 Windows
Windows Phone 寿终正寝了,这些经典机型你还记得吗?
不久前,随着最后一家WP手机厂商惠普宣布取消今后Windows Phone的研发计划,以及微软官方声明对WP8.1系统今后所有升级维护的终止,WP手机,作为曾经和安卓手机、苹果手机并驾齐驱的三大智能手机之一,正式寿终正寝。
1237 0
Windows Phone 寿终正寝了,这些经典机型你还记得吗?
|
XML 开发框架 前端开发
Windows Phone快速入门需掌握哪些能力
在此之前,先普及下Windows Phone的概念和开发工具的介绍。 Windows Phone是微软公司开发的手机操作系统,它将微软旗下的Xbox Live游戏、Xbox Music音乐与独特的视频体验集成至手机中。2012年6月21日,微软正式发布Windows Phone 8,采用和Windows 8相同的Windows NT内核,同时也针对市场的Windows Phone 7.5发布Windows Phone 7.8。
132 0
Windows Phone快速入门需掌握哪些能力
|
编解码 前端开发 JavaScript
Windows Phone 下开发 LBS 应用
基于位置的服务(Location Based Service,LBS),它是通过电信移动运营商的无线电通讯网络(如GSM网、CDMA网)或外部定位方式(如GPS)获取移动终端用户的位置信息(地理坐标,或大地坐标),在GIS(Geographic Information System,地理信息系统)平台的支持下,为用户提供相应服务的一种增值业务。
161 0
|
移动开发 Android开发 开发者
Windows Phone 8.1 新功能汇总 开发者预览版开放下载
在Build 2014大会上,微软正式发布了传闻已久的Windows Phone 8.1系统,所有的Windows Phone 8手机都可以升级,微软这次可谓是十分厚道。虽然并非迭代升级,但WP 8.1还是拥有很多重大更新,对于微软进一步完善移动平台拥有积极的意义。下面,就一起来了解一下WP 8.1的主要新特性。
230 0
Windows Phone 8.1 新功能汇总 开发者预览版开放下载

热门文章

最新文章