Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions Samples/StoragePickers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
## The Storage Pickers Samples

- Demonstrates the `Microsoft.Windows.Storage.Pickers` APIs inside a Windows App SDK app.
- Targets Windows App SDK **1.8 or later**.
- Three tabs showcase `FileOpenPicker`, `FileSavePicker`, and `FolderPicker` usage end to end.

## 📸 Screenshot of App Layout

![img](images/screenshot-storage-pickers.png)

## Deploy the Sample Packaged App Locally

1. Open `cpp-sample/FilePickersAppSinglePackaged.sln` or `cs-sample/FilePickersAppSinglePackaged.sln` in Visual Studio, right click on the project, select "Package and Publish" > "Create App Package"

![img](images/deploy1.png)

2. Select Sideloading > Next

![img](images/deploy2.png)

3. Create and Trust your own test certification

![img](images/deploy3.png)

![img](images/deploy4.png)

4. Create package

![img](images/deploy5.png)

5. Open the built result

![img](images/deploy6.png)

5. Run Install.ps1 in powershell

![img](images/deploy7.png)

*Note:*

If encountering error like below:

> Add-AppxPackage: Cannot find path 'C:\FilePickersAppSinglePackaged_1.0.1.0_x64_Debug_Test\Dependencies\x86\Microsoft.VCLibs.x86.Debug.14.00.appx C:\FilePickersAppSinglePackaged_1.0.1.0_x64_Debug_Test\Dependencies\x86\Microsoft.VCLibs.x86.Debug.14.00.Desktop.appx C:\FilePickersAppSinglePackaged_1.0.1.0_x64_Debug_Test\Dependencies\x64\Microsoft.VCLibs.x64.Debug.14.00.appx C:\FilePickersAppSinglePackaged_1.0.1.0_x64_Debug_Test\Dependencies\x64\Microsoft.VCLibs.x64.Debug.14.00.Desktop.appx' because it does not exist.

Replace lines 483-491 in `Add-AppDevPackage.ps1` with below script and try again:

```ps
if ($DependencyPackages.FullName.Count -gt 0)
{
Write-Host $UiStrings.DependenciesFound
$DependencyPackages.FullName


# Install dependencies one by one first
foreach ($dep in $DependencyPackages.FullName) {
echo "Installing dependency: $dep"
try {
Add-AppxPackage -Path $dep -ForceApplicationShutdown
echo "Successfully installed: $dep"
} catch {
echo "Failed to install dependency: $dep - $($_.Exception.Message)"
}
}

# Now install the main package
echo "Installing main package: $($DeveloperPackagePath.FullName)"
Add-AppxPackage -Path $DeveloperPackagePath.FullName -ForceApplicationShutdown
}
```

Screenshot of this error:
![img](images/deploy8.png)

Screenshot of this mitigation:

![img](images/deploy9.png)

With the dependency *.appx files correctly installed, the project should be debugged in Visual Studio smoothly.

![img](images/deploy10.png)


## 🚀 Run

1. Open `cpp-sample/FilePickersAppSinglePackaged.sln` or `cs-sample/FilePickersAppSinglePackaged.sln` in Visual Studio.
1. Restore NuGet packages and ensure the Windows App SDK 1.8 runtime is installed locally.
1. Build and run.


## More to explore

- [Microsoft.Windows.Storage.Pickers Namespace](https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers)
- [Design Specs of Microsoft.Windows.Storage.Pickers](https://github.com/microsoft/WindowsAppSDK/blob/release/1.8-stable/specs/Storage.Pickers/Microsoft.Windows.Storage.Pickers.md)
- [Windows App SDK](https://github.com/microsoft/WindowsAppSDK/)
24 changes: 24 additions & 0 deletions Samples/StoragePickers/cpp-sample/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<Application
x:Class="FilePickersAppSinglePackaged.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FilePickersAppSinglePackaged">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<!-- Other merged dictionaries here -->
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->

<!-- Define the TestGroupStyle here -->
<Style x:Key="TestGroupStyle" TargetType="StackPanel">
<Setter Property="Spacing" Value="8"/>
<Setter Property="Padding" Value="0,0,0,12"/>
<Setter Property="BorderBrush" Value="{ThemeResource DividerStrokeColorDefaultBrush}"/>
<Setter Property="BorderThickness" Value="0,0,0,1"/>
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
43 changes: 43 additions & 0 deletions Samples/StoragePickers/cpp-sample/App.xaml.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "pch.h"
#include "App.xaml.h"
#include "MainWindow.xaml.h"

using namespace winrt;
using namespace Microsoft::UI::Xaml;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace winrt::FilePickersAppSinglePackaged::implementation
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
App::App()
{
// Xaml objects should not call InitializeComponent during construction.
// See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent

#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException([](IInspectable const&, UnhandledExceptionEventArgs const& e)
{
if (IsDebuggerPresent())
{
auto errorMessage = e.Message();
__debugbreak();
}
});
#endif
}

/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
void App::OnLaunched([[maybe_unused]] LaunchActivatedEventArgs const& e)
{
window = make<MainWindow>();
window.Activate();
}
}
16 changes: 16 additions & 0 deletions Samples/StoragePickers/cpp-sample/App.xaml.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "App.xaml.g.h"

namespace winrt::FilePickersAppSinglePackaged::implementation
{
struct App : AppT<App>
{
App();

void OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const&);

private:
winrt::Microsoft::UI::Xaml::Window window{ nullptr };
};
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions Samples/StoragePickers/cpp-sample/FilePickersAppSinglePackaged.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35707.178 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FilePickersAppSinglePackaged", "FilePickersAppSinglePackaged.vcxproj", "{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|ARM64.ActiveCfg = Debug|ARM64
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|ARM64.Build.0 = Debug|ARM64
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|ARM64.Deploy.0 = Debug|ARM64
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|x64.ActiveCfg = Debug|x64
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|x64.Build.0 = Debug|x64
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|x64.Deploy.0 = Debug|x64
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|x86.ActiveCfg = Debug|Win32
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|x86.Build.0 = Debug|Win32
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|x86.Deploy.0 = Debug|Win32
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|ARM64.ActiveCfg = Release|ARM64
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|ARM64.Build.0 = Release|ARM64
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|ARM64.Deploy.0 = Release|ARM64
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|x64.ActiveCfg = Release|x64
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|x64.Build.0 = Release|x64
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|x64.Deploy.0 = Release|x64
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|x86.ActiveCfg = Release|Win32
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|x86.Build.0 = Release|Win32
{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|x86.Deploy.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Loading