windows phone 8.1開發:檔案選取器FileSavePicker

來源:互聯網
上載者:User

標籤:style   blog   color   os   io   檔案   ar   div   cti   

上一篇文章小夢分享了檔案選取器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個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.