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 Sample

Introduction

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

Project Structure

The sample includes the following key components:

Getting Started

  1. Open the solution in Visual Studio.
  2. Ensure you have the Windows SDK installed.
  3. Right-click on the WPF project and select "Publish" -> "Create App Packages".
  4. Follow the prompts to generate your MSIX package.
  5. 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
}

Further Resources