@@ -43,6 +43,9 @@ namespace winrt::PickerUsageApp::implementation
43
43
case 0 :
44
44
message = co_await OpenFileSDKClick (sender, args);
45
45
break ;
46
+ case 1 :
47
+ message = co_await SaveFileSDKClick ();
48
+ break ;
46
49
case 2 :
47
50
message = co_await OpenFolderSDKClick ();
48
51
break ;
@@ -69,6 +72,9 @@ namespace winrt::PickerUsageApp::implementation
69
72
case 0 :
70
73
message = co_await OpenFileUWPClick (sender, args);
71
74
break ;
75
+ case 1 :
76
+ message = co_await SaveFileUWPClick ();
77
+ break ;
72
78
case 2 :
73
79
message = co_await OpenFolderUWPClick ();
74
80
break ;
@@ -95,7 +101,7 @@ namespace winrt::PickerUsageApp::implementation
95
101
winrt::Windows::Storage::Pickers::FileOpenPicker picker{};
96
102
97
103
picker.as <::IInitializeWithWindow>()->Initialize (hWnd);
98
- SetPickerOptions <winrt::Windows::Storage::Pickers::FileOpenPicker, winrt::Windows::Storage::Pickers::PickerLocationId>(picker);
104
+ SetOpenPickerOptions <winrt::Windows::Storage::Pickers::FileOpenPicker, winrt::Windows::Storage::Pickers::PickerLocationId>(picker);
99
105
picker.ViewMode (Convert (m_ViewMode));
100
106
101
107
if (!m_MultipleSelect)
@@ -119,6 +125,33 @@ namespace winrt::PickerUsageApp::implementation
119
125
co_return L" no selection" ;
120
126
}
121
127
128
+ Windows::Foundation::IAsyncOperation<hstring> MainWindow::SaveFileUWPClick ()
129
+ {
130
+ auto windowNative = this ->m_inner .as <IWindowNative>();
131
+ HWND hWnd = nullptr ;
132
+ check_hresult (windowNative->get_WindowHandle (&hWnd));
133
+
134
+ winrt::Windows::Storage::Pickers::FileSavePicker picker{};
135
+ picker.FileTypeChoices ().Insert (L" Plain Text" , winrt::single_threaded_vector<hstring>({ L" .txt" }));
136
+
137
+ picker.as <::IInitializeWithWindow>()->Initialize (hWnd);
138
+ SetPickerOptions<winrt::Windows::Storage::Pickers::FileSavePicker, winrt::Windows::Storage::Pickers::PickerLocationId>(picker);
139
+
140
+ if (!m_MultipleSelect)
141
+ {
142
+ auto & file = co_await picker.PickSaveFileAsync ();
143
+ if (file != nullptr )
144
+ {
145
+ co_return file.Path ();
146
+ }
147
+ }
148
+ else
149
+ {
150
+ co_return L" File Save Picker does not support multi selection" ;
151
+ }
152
+ co_return L" no selection" ;
153
+ }
154
+
122
155
winrt::Windows::Foundation::IAsyncOperation<hstring> MainWindow::OpenFolderUWPClick ()
123
156
{
124
157
auto windowNative = this ->m_inner .as <IWindowNative>();
@@ -128,7 +161,7 @@ namespace winrt::PickerUsageApp::implementation
128
161
winrt::Windows::Storage::Pickers::FolderPicker picker{};
129
162
130
163
picker.as <::IInitializeWithWindow>()->Initialize (hWnd);
131
- SetPickerOptions <winrt::Windows::Storage::Pickers::FolderPicker, winrt::Windows::Storage::Pickers::PickerLocationId>(picker);
164
+ SetOpenPickerOptions <winrt::Windows::Storage::Pickers::FolderPicker, winrt::Windows::Storage::Pickers::PickerLocationId>(picker);
132
165
picker.ViewMode (Convert (m_ViewMode));
133
166
134
167
if (!m_MultipleSelect)
@@ -141,7 +174,7 @@ namespace winrt::PickerUsageApp::implementation
141
174
}
142
175
else
143
176
{
144
- co_return L" Folder multi selection is not support" ;
177
+ co_return L" Folder Picker does not support multi selection " ;
145
178
}
146
179
co_return L" no selection" ;
147
180
@@ -153,8 +186,7 @@ namespace winrt::PickerUsageApp::implementation
153
186
auto id = AppWindow ().Id ();
154
187
winrt::Microsoft::Storage::Pickers::FileOpenPicker picker{ id };
155
188
156
- SetPickerOptions<winrt::Microsoft::Storage::Pickers::FileOpenPicker, winrt::Microsoft::Storage::Pickers::PickerLocationId>(picker);
157
- // SetPickerOptions(picker);
189
+ SetOpenPickerOptions<winrt::Microsoft::Storage::Pickers::FileOpenPicker, winrt::Microsoft::Storage::Pickers::PickerLocationId>(picker);
158
190
picker.ViewMode (m_ViewMode);
159
191
if (!m_MultipleSelect)
160
192
{
@@ -177,12 +209,33 @@ namespace winrt::PickerUsageApp::implementation
177
209
co_return L" no selection" ;
178
210
}
179
211
212
+ Windows::Foundation::IAsyncOperation<hstring> MainWindow::SaveFileSDKClick ()
213
+ {
214
+ auto id = AppWindow ().Id ();
215
+ winrt::Microsoft::Storage::Pickers::FileSavePicker picker{ id };
216
+
217
+ SetPickerOptions<winrt::Microsoft::Storage::Pickers::FileSavePicker, winrt::Microsoft::Storage::Pickers::PickerLocationId>(picker);
218
+ if (!m_MultipleSelect)
219
+ {
220
+ auto & file = co_await picker.PickSaveFileAsync ();
221
+ if (file != nullptr )
222
+ {
223
+ co_return file.Path ();
224
+ }
225
+ }
226
+ else
227
+ {
228
+ co_return L" FileSavePicker does not support multi selection" ;
229
+ }
230
+ co_return L" no selection" ;
231
+ }
232
+
180
233
winrt::Windows::Foundation::IAsyncOperation<hstring> MainWindow::OpenFolderSDKClick ()
181
234
{
182
235
auto id = AppWindow ().Id ();
183
236
winrt::Microsoft::Storage::Pickers::FolderPicker picker{ id };
184
237
185
- SetPickerOptions <winrt::Microsoft::Storage::Pickers::FolderPicker, winrt::Microsoft::Storage::Pickers::PickerLocationId>(picker);
238
+ SetOpenPickerOptions <winrt::Microsoft::Storage::Pickers::FolderPicker, winrt::Microsoft::Storage::Pickers::PickerLocationId>(picker);
186
239
picker.ViewMode (m_ViewMode);
187
240
if (!m_MultipleSelect)
188
241
{
@@ -239,8 +292,6 @@ void winrt::PickerUsageApp::implementation::MainWindow::ViewModeSelectionChanged
239
292
default :
240
293
break ;
241
294
}
242
-
243
-
244
295
}
245
296
246
297
@@ -274,5 +325,3 @@ void winrt::PickerUsageApp::implementation::MainWindow::PickerTypeChanged(winrt:
274
325
{
275
326
m_PickerTypeIndex = sender.as <Microsoft::UI::Xaml::Controls::RadioButtons>().SelectedIndex ();
276
327
}
277
-
278
-
0 commit comments