Skip to content

Add FocusVisuals and TouchKeyboard samples (WinUI 3 migration from UWP)#649

Open
qiutongMS wants to merge 3 commits into
release/experimentalfrom
user/qiutongshen/migrate-uwp-sample
Open

Add FocusVisuals and TouchKeyboard samples (WinUI 3 migration from UWP)#649
qiutongMS wants to merge 3 commits into
release/experimentalfrom
user/qiutongshen/migrate-uwp-sample

Conversation

@qiutongMS

Copy link
Copy Markdown

Summary

Migrates two UWP samples to WinUI 3 / Windows App SDK:

These samples are referenced by 12+ pages under learn.microsoft.com/windows/apps/develop/input/. The existing UWP sample links point to archived repos that no longer build on modern tooling.

FocusVisuals Sample

Demonstrates custom focus visual styling in WinUI 3:

  • Custom focus visual properties (primary/secondary brush, thickness, margin)
  • Custom control with Template focus visual kind and rounded corners (WinUI 3 Fluent style)

TouchKeyboard Sample

Demonstrates software keyboard (SIP) interactions in WinUI 3:

  1. Auto display — touch keyboard appears/disappears based on input scope
  2. Show/Hide events — listening to InputPane.Showing/Hiding to adjust layout
  3. Programmatic show/hideInputPane.TryShow()/TryHide()
  4. Emoji keyboard — launching emoji panel via CoreInputView (requires package identity)

Notable technical details

  • Fixed .NET 9 COM interop breaking change: MarshalAs(UnmanagedType.HString) no longer works — replaced with manual WindowsCreateString/WindowsDeleteString + IntPtr marshaling
  • Supports both packaged and unpackaged modes (WindowsAppSDKSelfContained=true)
  • Scenario 4 (emoji keyboard) gracefully degrades in unpackaged mode with a user-facing warning

Testing

All scenarios verified on Windows 11 with mouse + touch input, in both packaged and unpackaged deployment modes.

Qiutong Shen and others added 2 commits June 30, 2026 16:55
Migrated from Windows-universal-samples/Samples/XamlFocusVisuals to WinUI 3.
- Two scenarios: custom focus visuals + system focus visuals on custom controls
- Adapted for CPM, EnablePreviewMsixTooling, net9.0 TFM
- Updated CheckBox template to use rounded corners (Fluent Design)
- Temporarily uncommented nuget.org in nuget.config for local dev

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Migrated from Windows-universal-samples/Samples/TouchKeyboard to WinUI 3.
- 4 scenarios: auto display, show/hide events, programmatic show/hide, emoji keyboard
- InputPane.GetForCurrentView() replaced with InputPaneInterop.GetForWindow()
- CoreInputView COM interop fixed for .NET 9 (manual HString + IntPtr marshaling)
- Adapted for CPM, EnablePreviewMsixTooling, net9.0 TFM
- Removed systemAIModels capability
- Graceful fallback when CoreInputView unavailable in unpackaged mode

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds two new WinUI 3 / Windows App SDK sample apps—FocusVisuals and TouchKeyboard—by migrating existing UWP samples so the docs can link to projects that build on modern tooling.

Changes:

  • Added a WinUI 3 TouchKeyboard sample with 4 scenarios demonstrating SIP show/hide behavior, events, and emoji keyboard invocation.
  • Added a WinUI 3 FocusVisuals sample demonstrating custom focus visuals and applying system focus visuals to a custom control.
  • Included single-project MSIX packaging artifacts and launch profiles to support packaged/unpackaged workflows.

Reviewed changes

Copilot reviewed 33 out of 52 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
Samples/TouchKeyboard/cs-winui/TouchKeyboard.sln Adds a solution for the TouchKeyboard WinUI 3 sample.
Samples/TouchKeyboard/cs-winui/TouchKeyboard.csproj Defines the TouchKeyboard WinUI 3 project (target framework, WinUI/App SDK packages, assets, MSIX capability).
Samples/TouchKeyboard/cs-winui/Scenario4_ShowView.xaml.cs Implements Scenario 4 logic to show the emoji keyboard via CoreInputView interop.
Samples/TouchKeyboard/cs-winui/Scenario4_ShowView.xaml Scenario 4 UI for triggering emoji keyboard on focus.
Samples/TouchKeyboard/cs-winui/Scenario3_ShowHideMethods.xaml.cs Implements Scenario 3: programmatic TryShow/TryHide behavior.
Samples/TouchKeyboard/cs-winui/Scenario3_ShowHideMethods.xaml Scenario 3 UI with storyboard and TextBox interaction.
Samples/TouchKeyboard/cs-winui/Scenario2_ShowHideEvents.xaml.cs Implements Scenario 2: InputPane Showing/Hiding event handling.
Samples/TouchKeyboard/cs-winui/Scenario2_ShowHideEvents.xaml Scenario 2 UI for observing InputPane events.
Samples/TouchKeyboard/cs-winui/Scenario1_Launch.xaml.cs Scenario 1 page code-behind (launch/intro).
Samples/TouchKeyboard/cs-winui/Scenario1_Launch.xaml Scenario 1 UI describing automatic touch keyboard behavior and a custom TextBox control.
Samples/TouchKeyboard/cs-winui/Properties/launchSettings.json Launch profiles for packaged vs unpackaged runs.
Samples/TouchKeyboard/cs-winui/Package.appxmanifest MSIX manifest for the TouchKeyboard sample.
Samples/TouchKeyboard/cs-winui/MainWindow.xaml.cs App shell window logic (navigation + status InfoBar).
Samples/TouchKeyboard/cs-winui/MainWindow.xaml App shell UI (title bar + NavigationView + content frame).
Samples/TouchKeyboard/cs-winui/CustomTextBox.cs Custom TextBox subclass used in Scenario 1.
Samples/TouchKeyboard/cs-winui/App.xaml.cs App startup logic for TouchKeyboard.
Samples/TouchKeyboard/cs-winui/App.xaml App resources setup for TouchKeyboard (WinUI resources).
Samples/TouchKeyboard/cs-winui/app.manifest Unpackaged app manifest settings (OS compatibility + DPI awareness).
Samples/FocusVisuals/cs-winui/Themes/Generic.xaml Adds a custom control template/style for the sample’s SocialMediaCounter control.
Samples/FocusVisuals/cs-winui/SocialMediaCounter.cs Implements the custom HyperlinkButton-derived control used to demonstrate system focus visuals.
Samples/FocusVisuals/cs-winui/Scenarios/CustomFocusVisualsPage.xaml.cs Code-behind for the “custom focus visuals” scenario page.
Samples/FocusVisuals/cs-winui/Scenarios/CustomFocusVisualsPage.xaml Scenario page demonstrating a custom CheckBox focus visual template.
Samples/FocusVisuals/cs-winui/Scenarios/CustomControlUsagePage.xaml.cs Code-behind for the “custom control usage” scenario page.
Samples/FocusVisuals/cs-winui/Scenarios/CustomControlUsagePage.xaml Scenario page applying system focus visuals to a custom control instance.
Samples/FocusVisuals/cs-winui/Properties/launchSettings.json Launch profiles for packaged vs unpackaged runs.
Samples/FocusVisuals/cs-winui/Package.appxmanifest MSIX manifest for the FocusVisuals sample.
Samples/FocusVisuals/cs-winui/MainWindow.xaml.cs App shell window logic (navigation).
Samples/FocusVisuals/cs-winui/MainWindow.xaml App shell UI (title bar + NavigationView + frame).
Samples/FocusVisuals/cs-winui/FocusVisualsSample.sln Adds a solution for the FocusVisuals WinUI 3 sample.
Samples/FocusVisuals/cs-winui/FocusVisualsSample.csproj Defines the FocusVisuals WinUI 3 project (WinUI/App SDK packages, assets, MSIX capability).
Samples/FocusVisuals/cs-winui/App.xaml.cs App startup logic for FocusVisuals.
Samples/FocusVisuals/cs-winui/App.xaml App resources setup for FocusVisuals (includes Generic.xaml).
Samples/FocusVisuals/cs-winui/app.manifest Unpackaged app manifest settings (OS compatibility + DPI awareness).

Comment thread Samples/TouchKeyboard/cs-winui/App.xaml.cs
Comment thread Samples/FocusVisuals/cs-winui/App.xaml.cs
Comment thread Samples/TouchKeyboard/cs-winui/TouchKeyboard.sln
Comment thread Samples/FocusVisuals/cs-winui/FocusVisualsSample.sln
Comment thread Samples/TouchKeyboard/cs-winui/Scenario4_ShowView.xaml.cs Outdated
Comment thread Samples/FocusVisuals/cs-winui/Scenarios/CustomControlUsagePage.xaml Outdated
Comment thread Samples/TouchKeyboard/cs-winui/Scenario2_ShowHideEvents.xaml
Comment thread Samples/TouchKeyboard/cs-winui/Scenario4_ShowView.xaml Outdated
Comment thread Samples/TouchKeyboard/cs-winui/Scenario3_ShowHideMethods.xaml Outdated
Comment thread Samples/TouchKeyboard/cs-winui/Scenario1_Launch.xaml Outdated
- Add copyright/MIT license headers to all C# and XAML files
- Add ARM64 build/deploy configurations to both .sln files
- Fix WindowsCreateString: use string.Length instead of hardcoded 51
- Add base.OnNavigatedTo/OnNavigatedFrom calls in Scenario2 and Scenario3
- Fix KeyDown/KeyUp event mismatch in Scenario3 XAML (KeyDown -> KeyUp)
- Rename generic 'Button' labels to 'Dismiss keyboard' for clarity
- Add AutomationProperties.Name to SocialMediaCounter custom control

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 33 out of 52 changed files in this pull request and generated 4 comments.

Comment on lines +32 to +35
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
_inputPane = InputPaneInterop.GetForWindow(hwnd);

_inputPane.Showing += OnShowing;
Comment on lines +33 to +35
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
_inputPane = InputPaneInterop.GetForWindow(hwnd);
}
Comment on lines +27 to +30
var window = MainWindow.Current;
if (window is null) return;

var hwnd = WindowNative.GetWindowHandle(window);
Comment on lines +20 to +23
<Image Height="30" Control.IsTemplateFocusTarget="True" Source="{Binding ShareImage, RelativeSource={RelativeSource TemplatedParent}}" />

<Path Data="M0.5,0.5 L155.5,0.5 L155.5,155.5 L0.5,155.5 L0.5,100 L-37.3739,77.3333 L0.416768,50 z" Stretch="Fill" Stroke="{ThemeResource SystemControlForegroundBaseHighBrush}" Height="20" Width="30" HorizontalAlignment="Left" UseLayoutRounding="False" Grid.Column="1"/>
<TextBlock Text="{Binding NumOfShares, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource CaptionTextBlockStyle}" Margin="11,6,0,0" Grid.Column="1" />
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