windows phone 8.1开发:文件选择器FileOpenPicker
原文出自:http://www.bcmeng.com/fileopenpicker/
今天小梦给大家分享一下 windows phone 8.1中的文件选择器,和之前的windows phone8的不同,在windows phone8中如果要选择照片,可以直接用照片选择器,但是这在windows phone8.1中没有了,windows phone8.1 增加了文件选择器.相比之下,文件选择器不仅可以选择照片,还可以选择各类文件,手机和SD卡都可以,还可以查找网路中其他设备所共享的文件,还可以在Onedrive上浏览并选择需要的文件.
文件选择器分为:FileOpenPicker和FileSavePicker俩类.前者用来打开已经存在的任何文件,后者可以创建新文件或者覆盖同名文件.
我们先来看FileOpenPicker.常用属性:
- FileTypeFilter:文件类型过滤器,是一个string类型的列表,每一个元素为一个有效的文件扩展名.
- CommitButtonText:提交按钮上显示的文本.
- ContinuationData: 利用ContinuationData 来记录一些信息,以保证应用恢复时能获取应用挂起的信息.
注意:SuggestedStartLocation和ViewMode属性在windows phone 8.1中是无效的!仅在windows 8.1中有效.
俩个方法:
- PickSingleFileAndContinue:选取单个文件并继续
- PickMultipleFilesAndContinue 选取多个文件并继续
下面我们来看一个具体示例,利用文件选择器选择一张照片:
首先实例化FileOpenPicker对象,设置文件类型,设置 ContinuationData
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.FileTypeFilter.Add(".jpg");
openPicker.ContinuationData["Operation"] = "Image";
openPicker.PickSingleFileAndContinue();
然后处理OnActivated事件:
protected override void OnActivated(IActivatedEventArgs args)
{ if (args is FileOpenPickerContinuationEventArgs)
{
Frame rootFrame = Window.Current.Content as Frame;
if (!rootFrame.Navigate(typeof(MainPage)))
{
throw new Exception("Failed to create target page");
} var p = rootFrame.Content as MainPage;
p.FilePickerEvent = (FileOpenPickerContinuationEventArgs)args;
} Window.Current.Activate();
}
最后在使用文件选择器的页面处理返回的数据:
private FileOpenPickerContinuationEventArgs _filePickerEventArgs = null;
public FileOpenPickerContinuationEventArgs FilePickerEvent
{
get { return _filePickerEventArgs; }
set
{
_filePickerEventArgs = value;
ContinueFileOpenPicker(_filePickerEventArgs);
}
} public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
{
if ((args.ContinuationData["Operation"] as string) == "Image" && args.Files != null && args.Files.Count > )
{
StorageFile file = args.Files[];
IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(fileStream);
image.Source = bitmapImage;
}
}
使用FileOpenPicker的方法就是这样,获取其他文件时,不同的地方是文件类型的设置以及返回数据的处理.
windows phone 8.1开发:文件选择器FileOpenPicker的更多相关文章
- windows phone 8.1开发:文件选择器FileSavePicker
上一篇文章小梦分享了文件选择器FileOpenPicker的用法,这篇文章我们继续分享FileSavePicker的用法,FileSavePicker的用法几乎和FileOpenPicker用法一模一 ...
- Windows Store App JavaScript 开发:选取文件和文件夹
前面提到过,文件打开选取器由FileOpenPicker类表示,用于选取或打开文件,而文件夹选取器由FolderPicker类表示,用来选取文件夹.在FileOpenPicker类中,pickSing ...
- Windows Phone 8初学者开发—第21部分:永久保存Wav音频文件
原文 Windows Phone 8初学者开发—第21部分:永久保存Wav音频文件 第21部分:永久保存Wav音频文件 原文地址:http://channel9.msdn.com/Series/Win ...
- Windows Phone 8初学者开发—第20部分:录制Wav音频文件
原文 Windows Phone 8初学者开发—第20部分:录制Wav音频文件 原文地址:http://channel9.msdn.com/Series/Windows-Phone-8-Develop ...
- Java开发桌面程序学习(五)——文件选择器和目录选择器的使用
选择器的使用 DirectoryChooser目录选择器官方文档 FileChooser文件选择器官方文档 文件选择器的使用 JavaFx中有个FileChoser,可以打开一个对话框来选择文件 Fi ...
- 《深入浅出Windows 10通用应用开发》
<深入浅出Windows 10通用应用开发>采用Windows 10的SDK进行重新改版,整合了<深入浅出Windows Phone 8.1应用开发>和<深入解析 ...
- Windows Phone 8初学者开发—第4部分:XAML简介
原文 Windows Phone 8初学者开发—第4部分:XAML简介 原文地址: http://channel9.msdn.com/Series/Windows-Phone-8-Developme ...
- 课程上线 -“新手入门 : Windows Phone 8.1 开发”
经过近1个月的准备和录制,“新手入门 : Windows Phone 8.1 开发”系列课程已经在Microsoft 虚拟学院上线,链接地址为:http://www.microsoftvirtuala ...
- ftpget 从Windows FTP服务端获取文件
/********************************************************************************* * ftpget 从Windows ...
随机推荐
- We Chall-Training: LSB-Writeup
MarkdownPad Document html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,ab ...
- 使用express.js框架一步步实现基本应用以及构建可扩展的web应用
最近过年在家有点懈怠,但是自己也不断在学习新的前端技术,在家琢磨了express.js的web框架. 框架的作用就是提高开发效率,快速产出结果.即使不使用框架,我们也会在开发过程中逐渐形成构成框架. ...
- context:annotation-config, mvc:annotation-driven, context:compont-scan 区别
当我们需要使用BeanPostProcessor时,直接在Spring配置文件中定义这些Bean显得比较笨拙,例如: 使用@Autowired注解,必须事先在Spring容器中声明AutowiredA ...
- 使用T4模板生成POCO类
为什么叫T4?因为简写为4个T. T4(Text Template Transformation Toolkit)是微软官方在VisualStudio 2008中开始使用的代码生成引擎.在 Visua ...
- Professional C# 6 and .NET Core 1.0 - 40 ASP.NET Core
本文内容为转载,重新排版以供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处:Professional C# 6 and .NET Core 1.0 - 40 ASP.NET Core --- ...
- Codeforces Good Bye 2016 题解
好久没有fst题了...比赛先A了前4题然后发现room里有人已经X完题了没办法只能去打E题,结果差一点点打完...然后C题fst掉了结果就掉rating 了...下面放题解 ### [A. New ...
- 纯css实现京东导航菜单
纯CSS代码实现导航菜单,推荐在chrome预览! 预览请点击这里:mygithub <!doctype html> <html lang="en"> &l ...
- 浅谈Jasmine的安装和拆卸
单元测试中,我们通常需要在执行测试代码前准备一些测试数据,建立测试场景,这些为了测试成功而所做的准备工作称为Test Fixture.而测试完毕后也需要释放运行测试所需的资源.这些铺垫工作占据的代码可 ...
- 了解 : 怎么处理jobbox status drop down list roll back
that.onStatusEnumChange = function (toStatus) { //设计理念是当completed 和 rejected 的状态下,是无法换状态 if (toStatu ...
- C#基础——结构体
集合:数组:同一类型,固定长度集合:不同类型,不固定长度 要使用集合,必须先引用命名空间:using System.Collections; 定义:ArrayList arr = new ArrayL ...