Select the type of the file to save in Xaml

Source: Internet
Author: User
Tags blank page

Front-end code: <Canvas Background = "{StaticResource AppBarBackgroundThemeBrush}"> <TextBox Name = "txtContent" Width = "1365" Height = "696" TextWrapping = "Wrap" FontSize = "18" Canvas. top = "1"/> <Button Content = "Save to file" Canvas. left = "710" FontSize = "15" Canvas. top = "702" Padding = "0.844" Click = "btnSave_Click" RenderTransformOrigin =, 0.395 "Height =" 60 "/> <TextBlock Name =" Msg "FontSize =" 20 "Canvas. left = "1015" Canvas. T Op = "722" RenderTransformOrigin = "-1.207, 0.583"/> <TextBox TextWrapping = "Wrap" Text = "multi-grid file storage is supported, you can write diaries, Word, Txt, and so on... for convenient user writing, come and try "Canvas. top = "712" Width = "574" Canvas. left = "10" Height = "46"/> </Canvas> </Page> background code: using System; using System. collections. generic; using System. IO; using System. linq; using Windows. foundation; using Windows. foundation. collections; using Windows. UI. xaml; using Windows. UI. xaml. cont Rols; using Windows. UI. xaml. controls. primitives; using Windows. UI. xaml. data; using Windows. UI. xaml. input; using Windows. UI. xaml. media; using Windows. UI. xaml. navigation; using Windows. storage; using Windows. storage. pickers; // "blank page" item template in http://go.microsoft.com/fwlink? Link id = 234238 describes how to choose to save the file {// <summary> /// for namespace, or navigate to a blank page inside the Frame. /// </Summary> public sealed partial class MainPage: Page {public MainPage () {this. initializeComponent ();} private async void btnSave_Click (object sender, RoutedEventArgs e) {if (this.txt Content. text. equals (string. empty) {return;} FileSavePicker picker = new FileSavePicker (); // The text picker displayed on the submit button. commitButtonText = "save"; // supported file type picker. fileTypeChoices. add ("text file", new string [] {". txt "} ); Picker. fileTypeChoices. add ("Word Document", new string [] {". doc "}); picker. fileTypeChoices. add ("WordPad", new string [] {". rtf "}); picker. fileTypeChoices. add ("document template", new string [] {". dot "}); picker. fileTypeChoices. add ("WPS", new string [] {". wps "}); picker. fileTypeChoices. add ("Word platform", new string [] {". wpt "}); picker. fileTypeChoices. add ("webpage", new string [] {". html "}); picker. fileTypeChoices. ad D ("data", new string [] {". data "}); picker. fileTypeChoices. add ("Database", new string [] {". dbf "}); picker. fileTypeChoices. add ("Diary", new string [] {". jnt "}); picker. fileTypeChoices. add ("extensible identification language", new string [] {". xml "}); // default display directory picker. suggestedStartLocation = PickerLocationId. desktop; // display the UI and return the StorageFile file = await picker. pickSaveFileAsync (); // write content to the file if (file! = Null) {await FileIO. WriteTextAsync (file, txtContent. Text, Windows. Storage. Streams. UnicodeEncoding. Utf8); this. Msg. Text = "the file is saved. ";}}}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.