原文出自: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的更多相关文章

  1. windows phone 8.1开发:文件选择器FileSavePicker

    上一篇文章小梦分享了文件选择器FileOpenPicker的用法,这篇文章我们继续分享FileSavePicker的用法,FileSavePicker的用法几乎和FileOpenPicker用法一模一 ...

  2. Windows Store App JavaScript 开发:选取文件和文件夹

    前面提到过,文件打开选取器由FileOpenPicker类表示,用于选取或打开文件,而文件夹选取器由FolderPicker类表示,用来选取文件夹.在FileOpenPicker类中,pickSing ...

  3. Windows Phone 8初学者开发—第21部分:永久保存Wav音频文件

    原文 Windows Phone 8初学者开发—第21部分:永久保存Wav音频文件 第21部分:永久保存Wav音频文件 原文地址:http://channel9.msdn.com/Series/Win ...

  4. Windows Phone 8初学者开发—第20部分:录制Wav音频文件

    原文 Windows Phone 8初学者开发—第20部分:录制Wav音频文件 原文地址:http://channel9.msdn.com/Series/Windows-Phone-8-Develop ...

  5. Java开发桌面程序学习(五)——文件选择器和目录选择器的使用

    选择器的使用 DirectoryChooser目录选择器官方文档 FileChooser文件选择器官方文档 文件选择器的使用 JavaFx中有个FileChoser,可以打开一个对话框来选择文件 Fi ...

  6. 《深入浅出Windows 10通用应用开发》

        <深入浅出Windows 10通用应用开发>采用Windows 10的SDK进行重新改版,整合了<深入浅出Windows Phone 8.1应用开发>和<深入解析 ...

  7. Windows Phone 8初学者开发—第4部分:XAML简介

    原文  Windows Phone 8初学者开发—第4部分:XAML简介 原文地址: http://channel9.msdn.com/Series/Windows-Phone-8-Developme ...

  8. 课程上线 -“新手入门 : Windows Phone 8.1 开发”

    经过近1个月的准备和录制,“新手入门 : Windows Phone 8.1 开发”系列课程已经在Microsoft 虚拟学院上线,链接地址为:http://www.microsoftvirtuala ...

  9. ftpget 从Windows FTP服务端获取文件

    /********************************************************************************* * ftpget 从Windows ...

随机推荐

  1. 一篇文章搞定css3 3d效果

    css3 3d学习心得 卡片反转 魔方 banner图 首先我们要学习好css3 3d一定要有一定的立体感 通过这个图片应该清楚的了解到了x轴 y轴 z轴是什么概念了. 首先先给大家看一个小例子: 卡 ...

  2. 计算机程序的思维逻辑 (66) - 理解synchronized

    上节我们提到了多线程共享内存的两个问题,一个是竞态条件,另一个是内存可见性,我们提到,解决这两个问题的一个方案是使用synchronized关键字,本节就来讨论这个关键字. 用法 synchroniz ...

  3. C++ 头文件系列(istream)

    1. 简介 其实叫它istream有点不合适,因为该头文件不仅定义了istream,还定义了iostream. 2. basic_istream模版 basic_istream继承自basic_ios ...

  4. Spark RDD编程核心

    一句话说,在Spark中对数据的操作其实就是对RDD的操作,而对RDD的操作不外乎创建.转换.调用求值. 什么是RDD RDD(Resilient Distributed Dataset),弹性分布式 ...

  5. spring和UEditor结合

    前言 春节无聊,就去弄一下富文本编辑器,然后百度了一番,很多说百度的UEditor不错,然后去官网照着文档弄一遍,是挺简单好用的.然后想把这玩意结合到自己的一个spring项目里面,果然还是在点上传图 ...

  6. 怎么写jquery插件

    1. 添加js文件到html文件中,放下面的两行到html文档底部,</body>之前. <script src="js/jquery-1.9.1.min.js" ...

  7. KVO的概述与使用

      一,概述 KVO,即:Key-Value Observing,它提供一种机制,当指定的对象的属性被修改后,则对象就会接受到通知.简单的说就是每次指定的被观察的对象的属性被修改后,KVO就会自动通知 ...

  8. android学习10——对顶点着器和片段着色器的理解

    图形都是点,线,面组成的.顶点着器指定了顶点的位置,大小和颜色. 看一个顶点着色器的代码 attribute vec4 a_Position; attribute float a_PointSize; ...

  9. Mixin模式:带实现的协议

    Mixin(织入)模式并不是GOF的<设计模式>归纳中的一种,但是在各种语言以及框架都会发现该模式(或者思想)的一些应用.简单来说,Mixin是带有全部实现或者部分实现的接口,其主要作用是 ...

  10. MySQL学习分享-->查询-->查询的分类

    MySQL的查询可以分为交叉联接.内联接.外联接.自然联接.straight_join 下面对于查询的学习,会用到以下四张表: create table t_commodity_type( `id` ...