从今天开发始,我们又开始新的征程,接下来的课程我们要熟悉一下启动器和选择器,其实二者是一样的,没有根本的区别,启动器是有返回结果的,如打开搜索应用程序进行搜索,而选择器是有返回内容的,如选择一张照片。
那么,启动器和选择器是啥玩意儿呢?其实我们可以很简单去理解,说白了,就是使用系自带的组件或应用程序。对的,就是这样,我说过,有时候很多概念只是名字上吓人罢了,实际用起来是非常简单的,比如这个启动器和选择器就是了。
到底是不是很简单,实践一下就知道了,本系列教程叫“轻松入门”,既然称得上是轻松,痛苦的事情不会叫大家去做,而MS一向注重用户体验,不会让大家痛苦的。
先来总结一下,使用启动器和选择器的方法是一样的,都是以下几步,不过选择器因为有返回内容,因此会多一步。
一、实例化组件,就是new一个;
二、设置相关参数或属性,比如你要打电话,你总得要设置一个号码吧,不然你打个鸟啊;
三、显示应用组件,既然调用了系统程序,让用户操作,当然要Show出来;
四、(可选)处理返回数据,这是选择器才有。
今天先讲第一个组件,BingMapsDirectionsTask,就是启动Bing地图对行车路线进行定位搜索,是啊,像导航系统吧?
有两种方法来使用该启动器,一是通过开始和结束标签,就是从哪里到哪里,如从武汉到上海,那么开始标签为Wuhan,结束标签为Shanghai;另一种方法是通开始和结束位置,如经度,纬度等。
首先,我们演示一下简单的,用标签来导航。
界面很简单了,相信通过前面的学习,大家都知道怎么弄了,只要能输入开始和结束标签即。
下面是后台C#代码:
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 LauncherSample
{
public partial class MapByLabel : PhoneApplicationPage
{
public MapByLabel()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
BingMapsDirectionsTask map = new BingMapsDirectionsTask();
map.Start = new LabeledMapLocation { Label = txtLabelStart.Text };
map.End = new LabeledMapLocation { Label = txtLabelEnd.Text };
map.Show();
}
}
}
记得引入Microsoft.Phone.Tasks空间,所有的启动器和选择器都在里面。
好接下来,我们用能过经度和纬度来定位的方法。
首先要添加一个引用,在项目中右击“引用”,添加引用,然后选择System.Device,确定。
接着做好界面,同上需要开始的经度纬度,以及结束位置的经纬度。
然后就是代码。
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;
using System.Device.Location;
namespace LauncherSample
{
public partial class BingMapSample : PhoneApplicationPage
{
public BingMapSample()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
BingMapsDirectionsTask bt = new BingMapsDirectionsTask();
// 开始位置
LabeledMapLocation locStart = new LabeledMapLocation();
locStart.Location = new GeoCoordinate(Convert.ToDouble(txtLatitudeStart.Text), Convert.ToDouble(txtLongitudeStart.Text));
// 结束位置
LabeledMapLocation locEnd = new LabeledMapLocation();
locEnd.Location = new GeoCoordinate(Convert.ToDouble(txtLatitudeEnd.Text), Convert.ToDouble(txtLongitudeEnd.Text));
// 设置属性
bt.Start = locStart;
bt.End = locEnd;
// 显示启动器
bt.Show();
}
}
}
分享到:
相关推荐
Windows_Phone_7_启动器与选择器
windows phone 开发 在线教程
对Windows Phone 7应用程序生命周期的深度剖析,在与硬件进行交互和使用Expression Blend来创建更丰富的用户界面方面提供的建议,这些都有助于你学习创建独特而又实用的Windows Phone 7应用程序。
Developers are racing to discover how to develop for Windows Phone 7—and there is no quicker resource to help you get up to speed than Windows Phone 7 Recipes. This book covers all aspects of ...
开发技术篇介绍了常用控件、布局管理、数据存储、图形动画、多媒体、启动器与选择器、手机感应编程、MVVM模式、Silverlight Toolkit组件和网络编程这些实用的编程知识; 开发实例篇以应用实例的方式综合地讲解了...
windows phone 开发书籍及资料
windowsphone开发:类库和案例[借鉴].pdf
windows phone8开发源代码 六:数据存储 七:图形动画 八:多媒体 九:启动器与选择器 十:手机感应编程
Windows Phone(简称:WP)是微软发布的一款手机操作系统,它将微软旗下的Xbox Live游戏、Xbox Music音乐与独特的视频体验集成至手机中。微软公司于2010年10月11日晚上9点30分正式发布了智能手机操作系统Windows ...
在开发Windows Phone应用程序的时候,或多或少会与图片打交道,下面总结下Windows Phone 中处理图片的一些技巧
Windows Phone开发-XNA基础
[Packt Publishing] Windows Phone 8 游戏开发教程 (英文版) [Packt Publishing] Windows Phone 8 Game Development (E-Book) ☆ 图书概要:☆ A practical guide to creating games for the Windows Phone 8 ...
内容提要: 本书对WindowsPhoneXNA游戏开发的流程进行了详细的讲解,对其核心内容和开发技巧进行了深入的说明。...本书还针对WindowsPhone8的新特性以及如何将WindowsPhone7游戏向WindowsPhone8上迁移做了详细的说明。
从monotouch和.net开发环境到objective-c和c#开发语言,从基于monotouch进行iphone开发的编程方法到应用程序的发布和销售等,《iPhone高级编程:使用Mono Touch和.NET/C#》涵盖了基于monotouch进行iphone应用程序...
WindowsPhone开发,包含聊天室案例开始,阅读器、天气预报、SignalR
Windows Phone7是微软重新打造windows mobile品牌之后推出的一款产品。
windows phone7 开发的案例,内有完整的工程项目。
仿Windows Phone博客导航源码 程序介绍: Windows Phone Blog Menu是一个Silverlight导航控件,看起来像Windows Phone 7。 控件中的tiles链接到web站点在你的博客中使用这个控件可以表达你对WP7的喜爱。 Windows...
今天,微软面向开发者正式发布了Windows Phone SDK 7.1开发工具的RTW版 Windows Phone SDK 7.1.1 更新在现有的 Windows Phone SDK 7.1 的基础上提供了更多功能。使用此更新,您可以更加轻松地开发可在 256 MB 设备...
windows phone开发实例源码 按照此专栏顺序排序http://blog.csdn.net/column/details/wp-comming.html 很感谢专栏博主