首页 > 代码库 > windows phone 8.1开发:文件选择器FileSavePicker
windows phone 8.1开发:文件选择器FileSavePicker
上一篇文章小梦分享了文件选择器FileOpenPicker的用法,这篇文章我们继续分享FileSavePicker的用法,FileSavePicker的用法几乎和FileOpenPicker用法一模一样.唯一的区别就是在FileOpenPicker中是通过FileTypeFilter属性添家字符串元素的,但是在FileSavePicker中是向FileTypeChoices属性表示的集合中添加元素的.FileTypeChoices是字典类型,因此它的每一个元素都必须具有唯一的键名,对应的值是IList<string>类型.
下面我们通过将textbox的内容存入一个txt文件来说明FileSavePicker的用法,过程和FileOpenPicker用法是一样的.
就把代码依次贴出来了:
private void saveButton_Click(object sender, RoutedEventArgs e) { FileSavePicker savePicker = new FileSavePicker(); savePicker.FileTypeChoices.Add("TXT", new List<string>() { ".txt" }); savePicker.SuggestedFileName = "小梦"; savePicker.ContinuationData["Operation"] = "Save"; savePicker.PickSaveFileAndContinue(); }
protected override void OnActivated(IActivatedEventArgs args) { if (args is FileSavePickerContinuationEventArgs) { Frame rootFrame = Window.Current.Content as Frame; if (!rootFrame.Navigate(typeof(MainPage))) { throw new Exception("Failed to create target page"); } var s = rootFrame.Content as MainPage; s.SavePickerArgs = (FileSavePickerContinuationEventArgs)args; } Window.Current.Activate(); }
private FileSavePickerContinuationEventArgs savePickerArgs; public FileSavePickerContinuationEventArgs SavePickerArgs { get { return savePickerArgs; } set { savePickerArgs = value; ContinuFileSavePicker(savePickerArgs); } } private async void ContinuFileSavePicker(FileSavePickerContinuationEventArgs args) { if (args.ContinuationData["Operation"] as string == "Save" && args.File != null) { StorageFile txtFile = args.File; await FileIO.WriteTextAsync(txtFile, this.text.Text.ToString(), Windows.Storage.Streams.UnicodeEncoding.Utf8); } }
windows phone 8.1开发:文件选择器FileSavePicker
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。