3 using System.Threading.Tasks;
4 using System.Runtime.InteropServices.WindowsRuntime;
5 using Windows.Foundation;
8 using Windows.UI.Xaml.Controls;
9 using Windows.UI.ViewManagement;
10 using Windows.Storage;
11 using Windows.Storage.Pickers;
12 using Windows.Graphics.Printing;
13 using Windows.Graphics.Printing.OptionDetails;
14 using FooEditEngine.UWP;
16 // 空白ページのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 を参照してください
21 /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
23 public sealed partial class MainPage : Page
25 MainViewModel vm = new MainViewModel();
28 this.InitializeComponent();
29 this.DataContext = this.vm;
30 //this.fooTextBox.AllowFocusOnInteraction = true;
31 PrintManager.GetForCurrentView().PrintTaskRequested += MainPage_PrintTaskRequested;
32 InputPane currentView = InputPane.GetForCurrentView();
33 currentView.Showing += currentView_Showing;
34 currentView.Hiding += currentView_Hiding;
37 void currentView_Hiding(InputPane sender, InputPaneVisibilityEventArgs args)
39 this.Margin = new Thickness(0);
40 args.EnsuredFocusedElementInView = true;
43 void currentView_Showing(InputPane sender, InputPaneVisibilityEventArgs args)
45 this.Margin = new Thickness(0, 0, 0, args.OccludedRect.Height);
46 args.EnsuredFocusedElementInView = true;
49 void MainPage_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
51 IAsyncAction async = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
53 var doc = this.vm.CurrentDocument;
54 var source = new DocumentSource(doc, new FooEditEngine.Padding(20, 20, 20, 20), this.FontFamily.Source, this.FontSize);
55 source.ParseHF = (s,e)=> { return e.Original; };
56 source.Header = "header";
57 source.Fotter = "footer";
58 source.Forground = new Windows.UI.Color() { R = 0, A = 255, B = 0, G = 0};
59 source.Keyword1 = new Windows.UI.Color() { R = 0, A = 255, B = 255, G = 0 };
60 source.Keyword2 = new Windows.UI.Color() { R = 128, A = 255, B = 255, G = 0 };
61 source.Literal = new Windows.UI.Color() { R = 128, A = 255, B = 128, G = 0 };
62 source.Comment = new Windows.UI.Color() { R = 255, A = 255, B = 0, G = 0 };
63 source.Url = new Windows.UI.Color() { R = 0, A = 255, B = 255, G = 0 };
65 PrintTask task = null;
66 task = args.Request.CreatePrintTask("test", (e) =>
70 task.Completed += async (s, e) => {
72 await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
73 System.Diagnostics.Debug.WriteLine("finished printing");
76 PrintOptionBuilder<DocumentSource> builder = new PrintOptionBuilder<DocumentSource>(source);
77 builder.BuildPrintOption(PrintTaskOptionDetails.GetFromPrintTaskOptions(task.Options));
79 Task t = WindowsRuntimeSystemExtensions.AsTask(async);
83 private async void Button_Click(object sender, RoutedEventArgs e)
85 var filepicker = new FileOpenPicker();
86 filepicker.FileTypeFilter.Add(".txt");
87 var file = await filepicker.PickSingleFileAsync();
90 using (var ws = await file.OpenAsync(FileAccessMode.Read))
91 using (var fs = new StreamReader(ws.AsStream()))
93 await this.vm.CurrentDocument.LoadAsync(fs, null);
95 this.vm.CurrentDocument.RequestRedraw();
99 private async void Print_Button_Click(object sender, RoutedEventArgs e)
101 await PrintManager.ShowPrintUIAsync();
104 private void Button_Click_New(object sender, RoutedEventArgs e)
106 this.vm.AddDocument();