zoukankan      html  css  js  c++  java
  • 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);
    
                }
    
            }
  • 相关阅读:
    小峰视频三:在eclipse中创建java类
    小峰视频二:java类的编译与解释
    小峰视频一:jdk环境变量的配置
    React/数据流
    React/组件
    React/生命周期
    React/虚拟DOM
    React/JSX简介
    12.朴素贝叶斯-垃圾邮件分类
    9、主成分分析
  • 原文地址:https://www.cnblogs.com/xdoudou/p/3936954.html
Copyright © 2011-2022 走看看