|
| 1 | +--- |
| 2 | +page_type: sample |
| 3 | +languages: |
| 4 | +- cppwinrt |
| 5 | +- cpp |
| 6 | +products: |
| 7 | +- windows |
| 8 | +- windows-app-sdk |
| 9 | +name: "Simple Island App" |
| 10 | +urlFragment: SimpleIslandApp |
| 11 | +description: "Shows how to add a WinAppSDK island to a simple Win32 app." |
| 12 | +extendedZipContent: |
| 13 | +- path: LICENSE |
| 14 | + target: LICENSE |
| 15 | +--- |
| 16 | + |
| 17 | +# Simple Island App |
| 18 | + |
| 19 | +This sample shows how to add a WinAppSDK island with Xaml content to a Win32 app. It was first created with the C++ "Windows Desktop Application" |
| 20 | +template in Visual Studio, which yields a boilerplate Win32 app that uses Windows APIs that have been around for a long time. |
| 21 | + |
| 22 | +This sample is an "unpackaged" app, so it will run like a win32 app that hasn't been changed for a while. |
| 23 | + |
| 24 | +This sample uses Windows App SDK as a "framework package". This means that the Windows App SDK runtime must be installed for it to run. |
| 25 | + |
| 26 | +## What is a WinAppSDK Island? |
| 27 | + |
| 28 | +A WinAppSDK island is a set of APIs that allows an app author to connect two UI frameworks together. This sample demonstrates how |
| 29 | +to connect Xaml content into a Win32 app. |
| 30 | + |
| 31 | +## Prerequisites |
| 32 | + |
| 33 | +* See [System requirements for Windows app development](https://docs.microsoft.com/windows/apps/windows-app-sdk/system-requirements). |
| 34 | +* Make sure that your development environment is set up correctly—see [Install tools for developing apps for Windows 10 and Windows 11](https://docs.microsoft.com/windows/apps/windows-app-sdk/set-up-your-development-environment). |
| 35 | + |
| 36 | +## Building and running the sample |
| 37 | + |
| 38 | +* Open the solution file (`.sln`) in Visual Studio. |
| 39 | +* Press Ctrl+Shift+B, or select **Build** \> **Build Solution**. |
| 40 | +* Press Ctrl+F5 to launch the app (without attaching a debugger) |
| 41 | + > Note: If the Windows App SDK runtime isn't installed on the machine, the user will see a message box directing them to a download link. |
| 42 | +* Press F5 to launch the app under a debugger. |
| 43 | + > Note: When running under a debugger, you may see an "Exception Thrown" dialog box in Visual Studio. You can safely press the "Continue" |
| 44 | + button to proceed. |
| 45 | +* To run from the command line or File Explorer, navigate to `<arch>/<config>/SimpleIslandApp` directory and run SimpleIslandApp.exe. |
| 46 | +* To deploy to another machine, copy the `<arch>/<config>/SimpleIslandApp` directory to that machine and run SimpleIslandApp.exe. The sample |
| 47 | +runs on Windows version 17763 and later. |
| 48 | + |
| 49 | +# How to add an Island with Xaml content to your own Win32 app |
| 50 | + |
| 51 | +Here's the basic steps to add an island to your own Win32 app, leveraging code from this sample: |
| 52 | +1. Add a NuGet reference to the Microsoft.WindowsAppSDK package (latest stable version). |
| 53 | +2. Add a NuGet reference to the Microsoft.Windows.CppWinRT package (latest stable version). |
| 54 | +3. Make some modifications to your vcxproj file and main message loop -- look for the tag "Island-support" in the sample code. |
| 55 | +4. Add an implementation for your Xaml App object. Feel free to copy the App.* files from this sample, as well as the vcxproj entries. |
| 56 | +The App object is needed for many of the Xaml controls to work, and it also enables metadata lookups for your app. |
| 57 | +5. Optional: Add a MainPage to create your first page of Xaml. You can copy it from this sample app. |
| 58 | +6. Modify your application to create your Xaml App object. After that, create a DesktopWindowXamlSource object to hold |
| 59 | +your Xaml content and position it within your HWND in your app wherever you'd like. |
| 60 | + |
0 commit comments