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 ...
随机推荐
- ubuntu/deepin制作快捷启动图标
默认情况下系统所有的快捷方式放在/usr/share/applications,打开该目录会看到大量的.desktop文件,每个文件便是一个快捷方式. 有时我们需要自己安装软件,然后添加快捷方式.文件 ...
- 华为oj---合并数组
题目标题: 将两个整型数组按照升序合并,并且过滤掉重复数组元素 详细描述: 接口说明 原型: voidCombineBySort(int* pArray1,intiArray1Num,int* pAr ...
- WinForm DataGridView增删改查
DataGridView连接数据库对表进行增删改查 一.绑定数据源 //做一个变量控制页面刷新 ; public Form1() { InitializeComponent(); } private ...
- SpringBoot 入门教程:集成mybatis,redis
SrpingBoot相较于传统的项目具有配置简单,能快速进行开发的特点,花更少的时间在各类配置文件上,更多时间在具体业务逻辑上. SPringBoot采用纯注解方式进行配置,不喜欢xml配置的同学得仔 ...
- (3)activiti流程的挂起和激活
有时候,我们需要对一个已经执行的流程进行暂停,而不是删除它,这个时候就需要我们调用activiti暂停和激活的api来操作他们 每启动一个流程实例,都会在该流程实例下产生相应的流程任务,处于1*多的关 ...
- EF操作扩展之async
EF的操作类网上很多类,我只是把我在平时项目中的类进行一些改进和扩展,扩展了部分同步和异步的EF操作 接口 /// <summary> /// 接口数据操作基础类 /// </sum ...
- Azure 基础:使用 powershell 创建虚拟网络
什么是虚拟网络 虚拟网络是您的网络在 Azure 云上的表示形式.您可以完全控制虚拟网络的 IP 地址.DNS 的设置.安全策略和路由表.您还可以更进一步,把虚拟网络划分为多个子网.然后用它们连接您的 ...
- PHP文件上传处理
web中,文件上传是一个很常用的功能.如:上传头像.上传图片.这些提交到后台的图片都要交给后端处理.php提供了几个上传处理的函数,我把它们封装成类,以便日后使用. 处理流程(可能有不合理的地方,用时 ...
- PPT中翻书动画的制作
一.新建一个空白的PowerPoint文档. 二.制作两个页面: 1.点击“自选图形”右边的小三角,选择“基本图形”下的“折角形”图形,在PowerPoint中画出一个书页样的图形,宽度最好小 ...
- 《汇编语言程序设计》——仿windows计算器
<汇编语言程序设计> ——计算器程序设计 目录 一. 题目与目标 1. 题目 2. 学习目的 二. 分析与设计 1. 系统分析 2. ...