原文出自: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. Wireshark网络抓包(三)——网络协议

    一.ARP协议 ARP(Address Resolution Protocol)地址解析协议,将IP地址解析成MAC地址. IP地址在OSI模型第三层,MAC地址在OSI第二层,彼此不直接通信: 在通 ...

  2. 神秘的ApplicationPoolIdentity再也不用妈妈担心程序池安全了

    在IIS 7和IIS 7.5中,我们可以为应用程序池设置一个特殊的Identity(用户标识):ApplicationPoolIdentity. 那么这个标识到底是什么意思?它是具体什么身份呢?这一讲 ...

  3. cmake的四个命令:add_compile_options、add_definitions、target_compile_definitions、build_command

    cmake的四个命令:add_compile_options.add_definitions.target_compile_definitions.build_command add_compile_ ...

  4. session工作原理简介

    session是什么 首先,我们需要知道session是什么.有比较专业的人将session称之为会话控制.说实在的,如果这么说的话,我也不清楚session到底算是什么. 其实session是一个存 ...

  5. Angular实现购物车计算

    使用AngularJS实现一个简单的购物车,主要感受强大的双向绑定和只关注对象不关注界面特性. 先看看界面: 点击+-操作和删除: 这些全部只需要操作数据源就行,不需要关注界面. 实现过程: 一.使用 ...

  6. JS特效——图片水平滚动

    具体源码如下: <!doctype html> <html lang="en"> <head> <meta http-equiv=&quo ...

  7. 转:frame和iframe的区别

    1.frame不能脱离frameSet单独使用,iframe可以: 2.frame不能放在body中:如下可以正常显示: <!--<body>--> <frameset ...

  8. Spark性能优化之道——解决Spark数据倾斜(Data Skew)的N种姿势

    原创文章,同步首发自作者个人博客转载请务必在文章开头处注明出处. 摘要 本文结合实例详细阐明了Spark数据倾斜的几种场景以及对应的解决方案,包括避免数据源倾斜,调整并行度,使用自定义Partitio ...

  9. ABP入门系列(13)——Redis缓存用起来

    ABP入门系列目录--学习Abp框架之实操演练 源码路径:Github-LearningMpaAbp 1. 引言 创建任务时我们需要指定分配给谁,Demo中我们使用一个下拉列表用来显示当前系统的所有用 ...

  10. 11g R2 RAC启动关闭步骤

    1.关闭监听 /u01/app/11.2.0/grid/bin/srvctl stop listener -n redhat-rac01 /u01/app/11.2.0/grid/bin/srvctl ...