WPF Desktop Bridge Details
Sample Name: WPF Desktop Bridge Integration
Description: This sample demonstrates how to integrate a Windows Presentation Foundation (WPF) application with the Windows Desktop Bridge, enabling it to be packaged and distributed through the Microsoft Store. It covers essential aspects like manifest generation, resource handling, and communication between the packaged app and the OS.
Technologies: WPF, Visual Studio, Windows SDK, Desktop Bridge
Last Updated: October 26, 2023
Download SampleIntroduction
The Windows Desktop Bridge allows developers to modernize existing desktop applications by packaging them into an MSIX format, making them discoverable and manageable through the Microsoft Store. This sample focuses specifically on adapting WPF applications for this process.
Key Concepts Demonstrated
- MSIX Packaging: Learn how to create an
.appxmanifest
file that correctly declares your WPF application's capabilities and dependencies. - Resource Management: Understand how resources like assets, configuration files, and settings are handled when packaged with the Desktop Bridge.
- Registry and File System Virtualization: Explore how the Desktop Bridge virtualizes access to the registry and file system to ensure compatibility.
- Background Tasks and Activation: See examples of how to implement background tasks and handle different activation types within a packaged WPF app.
- Application Lifecycle Management: Discover best practices for managing the lifecycle of your WPF application when it's running in a sandboxed environment.
Project Structure
The sample includes the following key components:
YourWpfApp.csproj
: The main project file for your WPF application.App.xaml
andApp.xaml.cs
: The application entry point.MainWindow.xaml
andMainWindow.xaml.cs
: The main window of the application.Package.appxmanifest
: The manifest file generated for MSIX packaging.Assets
folder: Contains icons and other assets required for the application package.
Getting Started
- Open the solution in Visual Studio.
- Ensure you have the Windows SDK installed.
- Right-click on the WPF project and select "Publish" -> "Create App Packages".
- Follow the prompts to generate your MSIX package.
- The sample includes a pre-configured manifest file that you can adapt for your own projects.
Code Snippets
Example Manifest Entry
Here's a snippet from a typical Package.appxmanifest
file for a WPF application:
<Application Id="App" Executable="YourWpfApp.exe" EntryPoint="YourWpfApp.App">
<uap:VisualAssets IconSize="150" Square150x150Logo="Assets\StoreLogo.png" />
</Application>
<Extensions>
<Extension Category="windows.activatableClass.inProcessServer">
<InProcessServer Argument="1" ClassId="your-unique-guid">
<Path DesktopName="YourWpfApp.exe" />
</InProcessServer>
</Extension>
</Extensions>
Handling File Access
When dealing with files that might be in restricted locations, use the Windows.Storage
APIs for robust access:
using Windows.Storage;
using System.Threading.Tasks;
public async Task ReadFileAsync(string filename)
{
StorageFolder appFolder = await StorageFolder.GetFolderForUserAsync(Windows.System.User.FindAllAsync().FirstOrDefault());
StorageFile file = await appFolder.GetFileAsync(filename);
string content = await FileIO.ReadTextAsync(file);
// Process content
}