修订版 | 74e1d6edb76d6e8281138b0a34e29e54cfc14998 (tree) |
---|---|
时间 | 2020-08-23 14:55:05 |
作者 | test <test@yaho...> |
Commiter | test |
関連付けからの起動もできるようにした
@@ -32,10 +32,6 @@ namespace Test | ||
32 | 32 | this.InitializeComponent(); |
33 | 33 | this.DataContext = this.vm; |
34 | 34 | //this.fooTextBox.AllowFocusOnInteraction = true; |
35 | - PrintManager.GetForCurrentView().PrintTaskRequested += MainPage_PrintTaskRequested; | |
36 | - InputPane currentView = InputPane.GetForCurrentView(); | |
37 | - currentView.Showing += currentView_Showing; | |
38 | - currentView.Hiding += currentView_Hiding; | |
39 | 35 | } |
40 | 36 | |
41 | 37 | protected override async void OnNavigatedTo(NavigationEventArgs e) |
@@ -50,8 +46,7 @@ namespace Test | ||
50 | 46 | foreach (var file in fileargs.Files) |
51 | 47 | { |
52 | 48 | StorageApplicationPermissions.MostRecentlyUsedList.Add(file, "mrufile"); |
53 | - this.vm.AddDocument(); | |
54 | - await LoadFile(this.vm.CurrentDocument, file as IStorageFile); | |
49 | + await this.vm.AddDocumentFromFile(file as IStorageFile); | |
55 | 50 | } |
56 | 51 | |
57 | 52 | } |
@@ -59,6 +54,20 @@ namespace Test | ||
59 | 54 | { |
60 | 55 | this.vm.Initalize(); |
61 | 56 | } |
57 | + | |
58 | + PrintManager.GetForCurrentView().PrintTaskRequested += MainPage_PrintTaskRequested; | |
59 | + InputPane currentView = InputPane.GetForCurrentView(); | |
60 | + currentView.Showing += currentView_Showing; | |
61 | + currentView.Hiding += currentView_Hiding; | |
62 | + } | |
63 | + | |
64 | + protected override void OnNavigatedFrom(NavigationEventArgs e) | |
65 | + { | |
66 | + base.OnNavigatedFrom(e); | |
67 | + PrintManager.GetForCurrentView().PrintTaskRequested -= MainPage_PrintTaskRequested; | |
68 | + InputPane currentView = InputPane.GetForCurrentView(); | |
69 | + currentView.Showing -= currentView_Showing; | |
70 | + currentView.Hiding -= currentView_Hiding; | |
62 | 71 | } |
63 | 72 | |
64 | 73 | void currentView_Hiding(InputPane sender, InputPaneVisibilityEventArgs args) |
@@ -112,20 +121,7 @@ namespace Test | ||
112 | 121 | var filepicker = new FileOpenPicker(); |
113 | 122 | filepicker.FileTypeFilter.Add(".txt"); |
114 | 123 | var file = await filepicker.PickSingleFileAsync(); |
115 | - await LoadFile(this.vm.CurrentDocument, file); | |
116 | - } | |
117 | - | |
118 | - private async Task LoadFile(FooEditEngine.Document doc,IStorageFile file) | |
119 | - { | |
120 | - if (file != null) | |
121 | - { | |
122 | - using (var ws = await file.OpenAsync(FileAccessMode.Read)) | |
123 | - using (var fs = new StreamReader(ws.AsStream())) | |
124 | - { | |
125 | - await doc.LoadAsync(fs, null); | |
126 | - } | |
127 | - doc.RequestRedraw(); | |
128 | - } | |
124 | + await this.vm.AddDocumentFromFile(file); | |
129 | 125 | } |
130 | 126 | |
131 | 127 | private async void Print_Button_Click(object sender, RoutedEventArgs e) |
@@ -7,12 +7,13 @@ using System.Text; | ||
7 | 7 | using System.Threading.Tasks; |
8 | 8 | using FooEditEngine; |
9 | 9 | using FooEditEngine.UWP; |
10 | +using Windows.Storage; | |
10 | 11 | |
11 | 12 | namespace Test |
12 | 13 | { |
13 | 14 | class MainViewModel : INotifyPropertyChanged |
14 | 15 | { |
15 | - ObservableCollection<Document> _list = new ObservableCollection<Document>(); | |
16 | + static ObservableCollection<Document> _list = new ObservableCollection<Document>(); | |
16 | 17 | |
17 | 18 | public MainViewModel() |
18 | 19 | { |
@@ -22,7 +23,7 @@ namespace Test | ||
22 | 23 | { |
23 | 24 | get |
24 | 25 | { |
25 | - return this._list; | |
26 | + return MainViewModel._list; | |
26 | 27 | } |
27 | 28 | } |
28 | 29 |
@@ -61,19 +62,35 @@ namespace Test | ||
61 | 62 | doc.AutoComplete = new AutoCompleteBox(doc); |
62 | 63 | doc.AutoComplete.Items = complete_collection; |
63 | 64 | doc.AutoComplete.Enabled = true; |
64 | - this._list.Add(doc); | |
65 | + MainViewModel._list.Add(doc); | |
65 | 66 | |
66 | 67 | doc = new Document() { Title = "test2" }; |
67 | - this._list.Add(doc); | |
68 | + MainViewModel._list.Add(doc); | |
68 | 69 | |
69 | - this.CurrentDocument = this._list[0]; | |
70 | + this.CurrentDocument = MainViewModel._list[0]; | |
70 | 71 | } |
71 | 72 | |
72 | 73 | public void AddDocument() |
73 | 74 | { |
74 | - var doc = new Document() { Title = "test" + this._list.Count }; | |
75 | - this._list.Add(doc); | |
76 | - this.CurrentDocument = this._list.Last(); | |
75 | + var doc = new Document() { Title = "test" + MainViewModel._list.Count }; | |
76 | + MainViewModel._list.Add(doc); | |
77 | + this.CurrentDocument = MainViewModel._list.Last(); | |
78 | + } | |
79 | + | |
80 | + public async Task AddDocumentFromFile(IStorageFile file) | |
81 | + { | |
82 | + if (file != null) | |
83 | + { | |
84 | + var doc = new Document() { Title = "test" + MainViewModel._list.Count }; | |
85 | + using (var ws = await file.OpenAsync(FileAccessMode.Read)) | |
86 | + using (var fs = new StreamReader(ws.AsStream())) | |
87 | + { | |
88 | + await doc.LoadAsync(fs, null); | |
89 | + } | |
90 | + doc.RequestRedraw(); | |
91 | + MainViewModel._list.Add(doc); | |
92 | + this.CurrentDocument = MainViewModel._list.Last(); | |
93 | + } | |
77 | 94 | } |
78 | 95 | |
79 | 96 | private void OnPropertyChanged(object sender, [System.Runtime.CompilerServices.CallerMemberName] string name = "") |