Skip to content

Use XamlHostingKit for UWP hosting - #31

Open
0x5bfa wants to merge 7 commits into
mainfrom
xamlhostingkit
Open

Use XamlHostingKit for UWP hosting#31
0x5bfa wants to merge 7 commits into
mainfrom
xamlhostingkit

Conversation

@0x5bfa

@0x5bfa 0x5bfa commented Aug 25, 2026

Copy link
Copy Markdown
Owner

Fixes

  • Replaces the UWP DesktopWindowXamlSource host and manual Win32 message loop with XamlHostingKit.
  • Adds XamlIslandApplication.Start and XamlIslandApplication.CreateWindow for main and additional System XAML threads.
  • Preserves desktop flyout positioning, clipping, activation modes, focus, theme notifications, and host-window cleanup on the XamlHostingKit window.
  • Registers the UWP library types with the app XAML metadata provider so hosted views can resolve DesktopFlyout and DesktopMenuFlyout.
  • Loads a separate flyout resource dictionary for every XamlHostingKit window, avoiding cross-thread application resources while keeping control templates available.
  • Adds self-contained UWP theme resources for the WinUI brush and corner-radius keys used by the flyout templates.
  • Installs a CoreDispatcher synchronization context on every hosted XAML thread so asynchronous show and hide work resumes on the correct thread.
  • Dispatches tray-icon left-click handling to the flyout's dispatcher and keeps the sample flyout open across XamlHostingKit's initial CoreWindow deactivation.
  • Initializes hidden UWP control templates safely before first display and guards menu opening until its target is ready.
  • Queues flyout and menu Show() calls made during asynchronous content attachment and replays them after the initial XamlHostingKit activation cycle.
  • Maps UWP XamlSourceFocusNavigationReason values to descendant and directional focus navigation.
  • Adds the XamlHostingKit dependency and updates CsWinRT to the compatible projection version.
  • Refactors the UWP sample to instantiate its flyout and menu on their own XAML threads.
  • Moves the UWP sample flyout islands and tray menu into CustomizableFlyout.xaml and MainDesktopMenuFlyout.xaml, matching the WASDK sample structure.
  • Consolidates the UWP executable, MSIX manifest, tray icon, and package assets into DesktopFlyouts.Uwp.Sample.App.
  • Removes the separate UWP TrayHost and Windows Application Packaging projects.
  • Removes the unrelated secondary UWP app and tif-secondaryapp: protocol activation demo.
  • Uses the UWP toolchain's implicit single-project MSIX BuildTools version, avoiding mixed targets and task assemblies in Visual Studio.
  • Includes all package assets in the generated MSIX.
  • Updates UWP startup, message-loop, project-layout, and validation documentation.

Steps to validate

  1. Restore the UWP sample with Visual Studio MSBuild: msbuild samples/DesktopFlyouts.Uwp.Sample.App/DesktopFlyouts.Uwp.Sample.App.csproj /t:Restore /p:Platform=x64.
  2. Build Uno: dotnet msbuild /restore:false src/DesktopFlyouts.Uno/DesktopFlyouts.Uno.csproj /p:Configuration=Debug /p:Platform=x64 /p:AppxBundle=Never.
  3. Build WinUI 3: dotnet msbuild /restore:false samples/DesktopFlyouts.Wasdk.Sample.App/DesktopFlyouts.Wasdk.Sample.App.csproj /p:Configuration=Debug /p:Platform=x64 /p:AppxBundle=Never.
  4. Build the UWP library: dotnet msbuild /restore:false src/DesktopFlyouts.Uwp/DesktopFlyouts.Uwp.csproj /p:Configuration=Debug /p:Platform=x64 /p:AppxBundle=Never.
  5. Generate the x64 Debug UWP MSIX with Visual Studio MSBuild: msbuild samples/DesktopFlyouts.Uwp.Sample.App/DesktopFlyouts.Uwp.Sample.App.csproj /p:Configuration=Debug /p:Platform=x64 /p:GenerateAppxPackageOnBuild=true /p:AppxPackageSigningEnabled=false /p:AppxBundle=Never /restore:false.
  6. Unpack and register the generated development MSIX, then launch it through shell:AppsFolder; do not run the packaged executable directly.
  7. Left-click the tray icon and confirm the flyout opens; left-click it again and confirm it closes.
  8. Right-click the tray icon and confirm the menu flyout opens and responds.
  9. Confirm DesktopFlyouts.Uwp.Sample.App remains responsive and that the Windows Application event log contains no new DesktopFlyouts errors.
  10. Launch the packaged WinUI 3 sample through shell:AppsFolder and confirm it is responsive with a non-zero window handle.
  11. Run git diff --check and verify changed text files report w/crlf from git ls-files --eol.

Copilot AI lite review requested due to automatic review settings August 25, 2026 12:43

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 70aecda89e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread samples/DesktopFlyouts.Uwp.Sample.App/App.xaml Outdated
Comment thread src/DesktopFlyouts.Shared/XamlIslandHostWindow.Uwp.cs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical resource and flyout-readiness issues remain unresolved, along with moderate theme and focus regressions.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR replaces manual UWP XAML-island hosting and the Win32 message loop with XamlHostingKit, while refactoring the tray sample, dependencies, and documentation.

Changes:

  • Adds XamlHostingKit-based UWP hosting and window-thread APIs.
  • Updates flyout readiness, focus, activation, theme, and cleanup handling.
  • Refactors the UWP tray-host sample and documentation.
File summaries
File Summary
src/DesktopFlyouts.Uwp/DesktopFlyouts.Uwp.csproj Adds hosting and compatible projection dependencies.
src/DesktopFlyouts.Shared/XamlIslandHostWindow.X11.cs Adds initialization state.
src/DesktopFlyouts.Shared/XamlIslandHostWindow.Uwp.cs Implements XamlHostingKit hosting; async readiness and focus behavior require changes.
src/DesktopFlyouts.Shared/XamlIslandHostWindow.cs Restricts the legacy host to WASDK and tracks initialization.
src/DesktopFlyouts.Shared/XamlIslandApplication.cs Adds UWP startup and window creation APIs.
src/DesktopFlyouts.Shared/DesktopMenuFlyout.cs Adds readiness checks; the target must also be attached before ShowAt.
src/DesktopFlyouts.Shared/DesktopFlyouts.Shared.projitems Includes the UWP host implementation.
src/DesktopFlyouts.Shared/DesktopFlyout.cs Uses host readiness checks.
samples/DesktopFlyouts.Uwp.Sample.TrayHost/Program.cs Starts the tray host through XamlHostingKit.
samples/DesktopFlyouts.Uwp.Sample.TrayHost/MainDesktopMenuFlyout.xaml.cs Removes obsolete code-behind.
samples/DesktopFlyouts.Uwp.Sample.TrayHost/MainDesktopMenuFlyout.xaml Removes declarative menu markup.
samples/DesktopFlyouts.Uwp.Sample.TrayHost/MainDesktopFlyout.xaml.cs Removes obsolete code-behind.
samples/DesktopFlyouts.Uwp.Sample.TrayHost/MainDesktopFlyout.xaml Removes declarative flyout markup.
samples/DesktopFlyouts.Uwp.Sample.TrayHost/DesktopFlyouts.Uwp.Sample.TrayHost.csproj Updates UWP build configuration.
samples/DesktopFlyouts.Uwp.Sample.TrayHost/App.xaml.cs Builds and dispatches flyouts; theme-aware background handling requires changes.
samples/DesktopFlyouts.Uwp.Sample.TrayHost/App.xaml Simplifies resources; required XAML control resources must be retained or replaced.
README.md Documents UWP startup.
docs/getting-started.md Adds UWP hosting instructions.
docs/focus-and-activation.md Updates message-loop guidance.
Directory.Packages.props Updates package versions.
.nuget/README.md Documents packaged UWP usage.
Review details
  • Files reviewed: 21/21 changed files
  • Comments generated: 5
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread samples/DesktopFlyouts.Uwp.Sample.App/App.xaml Outdated
Comment thread samples/DesktopFlyouts.Uwp.Sample.App/App.xaml.cs Outdated
Comment thread src/DesktopFlyouts.Shared/DesktopMenuFlyout.cs
Comment thread src/DesktopFlyouts.Shared/XamlIslandHostWindow.Uwp.cs
Comment thread src/DesktopFlyouts.Shared/XamlIslandHostWindow.Uwp.cs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants