OSDN Git Service

23d291816a456a8d8687a91f95baf4689e81e060
[fooeditengine/FooEditEngine.git] / UWP / Test / MainPage.xaml.cs
1 using System;
2 using System.IO;
3 using System.Runtime.InteropServices.WindowsRuntime;
4 using Windows.UI.Xaml;
5 using Windows.UI.Xaml.Controls;
6 using Windows.Storage;
7 using Windows.Storage.Pickers;
8 using Windows.Graphics.Printing;
9 using FooEditEngine.UWP;
10
11 // 空白ページのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 を参照してください
12
13 namespace Test
14 {
15     /// <summary>
16     /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
17     /// </summary>
18     public sealed partial class MainPage : Page
19     {
20         MainViewModel vm = new MainViewModel();
21         public MainPage()
22         {
23             this.InitializeComponent();
24             this.DataContext = this.vm;
25             this.fooTextBox.Document = this.vm.CurrentDocument;
26             PrintManager.GetForCurrentView().PrintTaskRequested += MainPage_PrintTaskRequested;
27         }
28
29         void MainPage_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
30         {
31             FooPrintText printtext = new FooPrintText();
32             printtext.Fotter = "fotter";
33             printtext.Header = "header";
34             printtext.Padding = new FooEditEngine.Padding(20, 20, 20, 20);
35             printtext.Print(args.Request, "Text Print", this.fooTextBox);
36         }
37
38         private async void Button_Click(object sender, RoutedEventArgs e)
39         {
40             var filepicker = new FileOpenPicker();
41             filepicker.FileTypeFilter.Add(".txt");
42             var file = await filepicker.PickSingleFileAsync();
43             if(file != null)
44             {
45                 using (var ws = await file.OpenAsync(FileAccessMode.Read))
46                 using (var fs = new StreamReader(ws.AsStream()))
47                 {
48                     await this.fooTextBox.LoadFileAsync(fs, null);
49                 }
50             }
51         }
52
53         private async void Print_Button_Click(object sender, RoutedEventArgs e)
54         {
55             await PrintManager.ShowPrintUIAsync();
56         }
57     }
58 }