Update sample for new functionalities of Storage.Picker APIs add in 2.0-exp2#582
Update sample for new functionalities of Storage.Picker APIs add in 2.0-exp2#582DinahK-2SO wants to merge 1 commit intorelease/experimentalfrom
Conversation
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.8.250907003" /> | ||
| <PackageReference Include="Microsoft.WindowsAppSDK" Version="2.0.0-experimental3" /> |
There was a problem hiding this comment.
TODO: change to exp4 after it's released.
haonanttt
left a comment
There was a problem hiding this comment.
It seems you need to rebase main first - there is already a merged PR to modify the packages.config version control to centralized package management, but your code is still with old packages.config mode
yeelam-gordon
left a comment
There was a problem hiding this comment.
Please fix according to latest vcxproj nuget package management.
Others looks good.
There was a problem hiding this comment.
Pull request overview
This PR updates the StoragePickers sample applications to demonstrate new functionalities added in WindowsAppSDK 2.0-experimental3, specifically for Storage.Picker APIs including FileOpenPicker, FileSavePicker, and FolderPicker.
Changes:
- Added support for new picker properties: SuggestedStartFolder, SuggestedFolder, and FileTypeChoices
- Implemented custom JSON deserialization methods to preserve insertion order for FileTypeChoices
- Updated package references from WindowsAppSDK 1.8.x to 2.0.0-experimental3
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 20 comments.
Show a summary per file
| File | Description |
|---|---|
| Samples/StoragePickers/cs-sample/MainWindow.xaml.cs | Added DeserializeJson method and integrated new picker properties across FileOpenPicker, FileSavePicker, and FolderPicker |
| Samples/StoragePickers/cs-sample/MainWindow.xaml | Added UI controls for SuggestedStartFolder and SuggestedFolder, renamed FileTypeChoices controls for clarity |
| Samples/StoragePickers/cs-sample/FilePickersAppSinglePackaged.csproj | Updated WindowsAppSDK package reference to version 2.0.0-experimental3 |
| Samples/StoragePickers/cpp-sample/MainWindow.xaml.h | Added method declarations for JSON deserialization and helper functions |
| Samples/StoragePickers/cpp-sample/MainWindow.xaml.cpp | Implemented JSON parsing logic for FileTypeChoices with insertion order preservation |
| Samples/StoragePickers/cpp-sample/MainWindow.xaml | Added OpenPickerFileTypeChoices controls and renamed SavePicker controls |
| Samples/StoragePickers/cpp-sample/packages.config | Updated all WindowsAppSDK and WebView2 package versions to 2.0.x-experimental |
| Samples/StoragePickers/cpp-sample/FilePickersAppSinglePackaged.vcxproj | Updated project import statements for new package versions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var choicesJson = (string)OpenPickerFileTypeChoicesInput.Text; | ||
| if (!string.IsNullOrEmpty(choicesJson)) | ||
| { | ||
| foreach(var choice in DeserizlizeJsonWithInsertionOrder(choicesJson)) |
There was a problem hiding this comment.
Method name has a spelling error. The method name "DeserizlizeJsonWithInsertionOrder" should be "DeserializeJsonWithInsertionOrder" (missing 'ia' in 'serialize'). This is called on line 247.
| foreach(var choice in DeserizlizeJsonWithInsertionOrder(choicesJson)) | |
| foreach(var choice in DeserializeJsonWithInsertionOrder(choicesJson)) |
| { | ||
| var choices = System.Text.Json.JsonSerializer.Deserialize(choicesJson, SourceGenerationContext.Default.DictionaryStringListString); | ||
| if (choices != null) | ||
| foreach(var choice in DeserizlizeJsonWithInsertionOrder(choicesJson)) |
There was a problem hiding this comment.
Method name has a spelling error. The method name "DeserizlizeJsonWithInsertionOrder" should be "DeserializeJsonWithInsertionOrder" (missing 'ia' in 'serialize'). This is called on line 308.
| foreach(var choice in DeserizlizeJsonWithInsertionOrder(choicesJson)) | |
| foreach (var choice in DeserializeJsonWithInsertionOrder(choicesJson)) |
|
|
||
| // This method parses the text input to preserve its insertion order. | ||
| // When developers coding with FileTypeChoices, the order can be directly reflected from code and this parsing is not required. | ||
| std::vector<std::pair<winrt::hstring, std::vector<winrt::hstring>>> MainWindow::DeserizeJsonInsertionOrder(std::wstring & jsonStr) |
There was a problem hiding this comment.
Method name has a spelling error. The method name "DeserizeJsonInsertionOrder" should be "DeserializeJsonInsertionOrder" (missing 'ial' in 'serialize').
| std::vector<std::pair<winrt::hstring, std::vector<winrt::hstring>>> MainWindow::DeserizeJsonInsertionOrder(std::wstring & jsonStr) | |
| std::vector<std::pair<winrt::hstring, std::vector<winrt::hstring>>> MainWindow::DeserializeJsonInsertionOrder(std::wstring & jsonStr) |
| } | ||
| catch (winrt::hresult_error const& ex) | ||
| { | ||
| std::wstring message = L"Error in New FileSavePicker: Unable to parse FileTypeChoices JSON - "; |
There was a problem hiding this comment.
Error message is misleading. The error states "Error in New FileSavePicker" but this code is in the NewPickSingleFile_Click handler for FileOpenPicker, not FileSavePicker. The error message should indicate "Error in New FileOpenPicker" instead.
| std::wstring message = L"Error in New FileSavePicker: Unable to parse FileTypeChoices JSON - "; | |
| std::wstring message = L"Error in New FileOpenPicker: Unable to parse FileTypeChoices JSON - "; |
| var choicesJson = (string)OpenPickerFileTypeChoicesInput.Text; | ||
| if (!string.IsNullOrEmpty(choicesJson)) | ||
| { | ||
| foreach(var choice in DeserizlizeJsonWithInsertionOrder(choicesJson)) |
There was a problem hiding this comment.
Method name has a spelling error. The method name "DeserizlizeJsonWithInsertionOrder" should be "DeserializeJsonWithInsertionOrder" (missing 'ia' in 'serialize'). This is called on line 177.
| foreach(var choice in DeserizlizeJsonWithInsertionOrder(choicesJson)) | |
| foreach (var choice in DeserializeJsonWithInsertionOrder(choicesJson)) |
| } | ||
|
|
||
| if (FileTypeChoicesCheckBox.IsChecked == true) | ||
| if (SavePickerFileTypeChoicesCheckBox.IsChecked == true) |
There was a problem hiding this comment.
The expression 'A == true' can be simplified to 'A'.
| picker.SuggestedStartLocation = GetSelectedNewLocationId(); | ||
| } | ||
|
|
||
| if (SuggestedStartFolderCheckBox.IsChecked == true) |
There was a problem hiding this comment.
The expression 'A == true' can be simplified to 'A'.
| picker.SuggestedStartFolder = SuggestedStartFolderInput.Text; | ||
| } | ||
|
|
||
| if (SuggestedFolderCheckBox.IsChecked == true) |
There was a problem hiding this comment.
The expression 'A == true' can be simplified to 'A'.
| picker.SuggestedStartLocation = GetSelectedNewLocationId(); | ||
| } | ||
|
|
||
| if (SuggestedStartFolderCheckBox.IsChecked == true) |
There was a problem hiding this comment.
The expression 'A == true' can be simplified to 'A'.
| picker.SuggestedStartFolder = SuggestedStartFolderInput.Text; | ||
| } | ||
|
|
||
| if (SuggestedFolderCheckBox.IsChecked == true) |
There was a problem hiding this comment.
The expression 'A == true' can be simplified to 'A'.
Update sample for new functionalities of Storage.Picker APIs add in 2.0-exp3:
FileOpenPicker.SuggestedStartFolder
FileOpenPicker.SuggestedFolder
FileOpenPIcker.FileTypeChoices
FileSavePicker.SuggestedStartFolder
FolderPicker.SuggestedStartFolder
FolderPicker.SuggestedFolder