Skip to content
General ITAdvanced

Why PreviewKeyDown Uses Tunneling Instead of Bubbling in WinUI 3

Quick Answer In WinUI 3, PreviewKeyDown and PreviewKeyUp use the tunneling routing strategy to give ancestor elements an opportunity to inspect or intercept ...

BI
Bison Technical Team Enterprise IT specialists
Updated 19 min read 0 total views
Structured technical guidanceSafety notes included where requiredSources cited when applicable

Quick Answer

In WinUI 3, PreviewKeyDown and PreviewKeyUp use the tunneling routing strategy to give ancestor elements an opportunity to inspect or intercept keyboard input before it is processed by the focused control.

Unlike these preview events, KeyDown and KeyUp use the bubbling routing strategy, in which events travel from their source toward ancestor elements.

Advertisement

This distinction is particularly useful because controls such as TextBox may handle keyboard input internally, preventing ordinary keyboard event handlers on parent elements from being invoked.

Microsoft documents this routing behavior but does not provide a definitive architectural explanation for why equivalent tunneling counterparts are not available for every routed input event in WinUI 3. The practical explanation is that keyboard preview events provide an early interception mechanism for focus-dependent keyboard input.

Understanding Routed Events in WinUI 3

A routed event is an event that can be processed by multiple elements within a XAML element hierarchy rather than exclusively by the element associated with the original interaction.

Routed events allow developers to centralize input handling in containers, pages and other ancestor elements without attaching separate application logic to every child control.

WinUI 3 keyboard input exposes two important routing strategies:

  • Tunneling: The event travels from the root toward the target element.
  • Bubbling: The event travels from its source toward ancestor elements.

Tunneling Events

A tunneling event allows elements higher in the hierarchy to receive input before the target element processes it through its normal input-handling mechanisms.

For example, consider a page containing a Grid, a StackPanel and a TextBox:

RootGrid
    |
    +-- Panel
          |
          +-- Input (TextBox)

When the TextBox has keyboard focus, the simplified routing sequence for PreviewKeyDown is:

RootGrid
    |
    v
Panel
    |
    v
Input (TextBox)

The parent containers receive the preview event before the focused TextBox receives its corresponding normal keyboard event.

Bubbling Events

A bubbling event follows the opposite direction. The event originates from the target element and proceeds toward its ancestors.

For the same element hierarchy, an unhandled KeyDown event follows this simplified route:

Input (TextBox)
    |
    v
Panel
    |
    v
RootGrid

This arrangement allows the focused control to retain its normal keyboard behavior while providing ancestor elements with an opportunity to respond to input that has not already been handled.

PreviewKeyDown vs. KeyDown in WinUI 3

Feature PreviewKeyDown KeyDown
Routing strategy Tunneling Bubbling
Routing direction Root toward the focused element Source toward the root
Processing stage Early keyboard input processing Normal keyboard input processing
Primary purpose Inspect or intercept keyboard input early Respond to keyboard input through normal event routing
Relationship to focused control handling Can run before normal control handling Ordinary handlers can be suppressed by control handling
Typical applications Container-level keyboard handling and custom navigation Control-specific and unhandled keyboard input
Event argument type KeyRoutedEventArgs KeyRoutedEventArgs

The same routing distinction applies to PreviewKeyUp and KeyUp when a keyboard key is released.

Why Does PreviewKeyDown Use Tunneling?

1. Keyboard Input Depends on Focus

Keyboard input is generally directed to the element that currently has keyboard focus.

For example, when a TextBox has focus, pressing a character key normally interacts with that TextBox. When focus moves to another control, subsequent keyboard input is directed to the newly focused element.

However, an application may need to respond to certain keys regardless of which child control has focus within a particular container.

Tunneling allows ancestor elements to inspect keyboard input before normal processing reaches the focused control, making it possible to implement behavior that applies to an entire section of the user interface.

2. Controls Can Handle Keyboard Input Internally

Many WinUI controls provide built-in keyboard functionality. A TextBox, for example, supports text editing, caret movement, text selection and common editing shortcuts.

Keyboard input associated with these operations may be marked as handled by the control.

Consequently, an ordinary KeyDown handler attached to a parent Grid may not receive the event.

Consider a TextBox containing text. When the user presses the Left Arrow key, the TextBox may use that input to move the caret. Its internal event handling can prevent ordinary ancestor KeyDown handlers from running.

A parent element's PreviewKeyDown handler can inspect that key before normal TextBox processing occurs.

3. Parent Elements Sometimes Require Processing Priority

Some application behaviors belong to a container rather than to an individual child control.

Examples include:

  • Closing an active application overlay with Escape.
  • Implementing specialized keyboard navigation within a composite control.
  • Handling keyboard input for a custom editing surface.
  • Inspecting keys for debugging or input diagnostics.
  • Applying application-specific keyboard interaction rules within a defined UI region.

A tunneling event provides an opportunity to implement this behavior before normal child-control processing consumes the input.

4. Keyboard Accelerators May Consume Input

WinUI supports keyboard accelerators through the KeyboardAccelerator class. These accelerators allow users to invoke application or control commands using keyboard shortcuts.

Built-in control accelerators can take precedence over application-defined shortcuts.

For example, a focused TextBox normally uses Ctrl+C to copy selected text. An application-defined shortcut using the same combination may not execute while that control has focus.

Preview keyboard events provide an earlier processing opportunity when an application genuinely needs to override such behavior.

Overriding familiar editing shortcuts is generally discouraged because it can interfere with established user expectations and accessibility.

Keyboard Event Routing Sequence in WinUI 3

The keyboard input pipeline involves preview events, accelerator processing, control-specific handling and ordinary routed keyboard events.

A simplified sequence for a key press is:

  1. WinUI identifies the keyboard input target.
  2. The PreviewKeyDown event travels toward the focused element.
  3. Applicable accelerator processing and normal control handling occur.
  4. Eligible KeyDown handlers execute along the bubbling route.
  5. Character input processing may follow when applicable.

When the key is released, the PreviewKeyUp and KeyUp events provide the corresponding preview and normal release notifications.

This is a simplified representation rather than a complete description of every internal processing stage. Accelerator evaluation, class handling and event delivery can depend on the element, key, focus state and whether earlier processing marked the input as handled.

Practical XAML and C++/WinRT Example

The following example demonstrates how tunneling and bubbling keyboard events behave within a simple WinUI 3 element hierarchy.

Prerequisites

  • A working WinUI 3 desktop application project.
  • A Windows App SDK version compatible with the project.
  • C++/WinRT development support in Visual Studio.
  • A MainWindow class generated by the WinUI application template.

Administrator privileges are not required to implement or run this example in a normal development environment.

Step 1: Configure the XAML Element Hierarchy

Add the following layout inside the existing Window element in MainWindow.xaml:

<Grid x:Name="RootGrid"
      PreviewKeyDown="OnPreviewKeyDown"
      KeyDown="OnKeyDown">

    <StackPanel x:Name="Panel"
                PreviewKeyDown="OnPreviewKeyDown"
                KeyDown="OnKeyDown"
                Spacing="12"
                Padding="20">

        <TextBox x:Name="Input"
                 Header="Keyboard Routing Test"
                 PlaceholderText="Type something here"
                 PreviewKeyDown="OnPreviewKeyDown"
                 KeyDown="OnKeyDown"/>

    </StackPanel>

</Grid>

All three elements subscribe to both keyboard events. Separate handler functions make it possible to identify whether a notification belongs to the preview phase or the normal keyboard event phase.

Step 2: Declare the Event Handlers

Add the following declarations to the existing MainWindow implementation structure in MainWindow.xaml.h:

void OnPreviewKeyDown(
    winrt::Windows::Foundation::IInspectable const& sender,
    winrt::Microsoft::UI::Xaml::Input::
        KeyRoutedEventArgs const& args);

void OnKeyDown(
    winrt::Windows::Foundation::IInspectable const& sender,
    winrt::Microsoft::UI::Xaml::Input::
        KeyRoutedEventArgs const& args);

Step 3: Implement the Event Handlers

Add the following Windows header to the implementation file, if it is not already available through the project's precompiled headers:

#include <windows.h>

Implement the following member functions in the existing implementation namespace in MainWindow.xaml.cpp:

void MainWindow::OnPreviewKeyDown(
    winrt::Windows::Foundation::IInspectable const& sender,
    winrt::Microsoft::UI::Xaml::Input::
        KeyRoutedEventArgs const& args)
{
    auto element =
        sender.try_as<
            winrt::Microsoft::UI::Xaml::FrameworkElement>();

    if (element)
    {
        OutputDebugStringW(L"PreviewKeyDown: ");
        OutputDebugStringW(element.Name().c_str());
        OutputDebugStringW(L"\n");
    }
}

void MainWindow::OnKeyDown(
    winrt::Windows::Foundation::IInspectable const& sender,
    winrt::Microsoft::UI::Xaml::Input::
        KeyRoutedEventArgs const& args)
{
    auto element =
        sender.try_as<
            winrt::Microsoft::UI::Xaml::FrameworkElement>();

    if (element)
    {
        OutputDebugStringW(L"KeyDown: ");
        OutputDebugStringW(element.Name().c_str());
        OutputDebugStringW(L"\n");
    }
}

The sender parameter identifies the element whose registered handler is currently executing. The Name() property identifies that element in the diagnostic output.

The OutputDebugStringW function sends diagnostic text to the debugger without changing the application's keyboard handling.

Step 4: Run and Verify the Application

  1. Build the application in Visual Studio.
  2. Start debugging by pressing F5.
  3. Open the Output window from the View menu if it is not already visible.
  4. Select the Debug output source.
  5. Click inside the TextBox to establish keyboard focus.
  6. Press an individual key that is not consumed by the control or an accelerator.
  7. Review the order of the diagnostic messages.

Expected Output for an Unhandled Key

PreviewKeyDown: RootGrid
PreviewKeyDown: Panel
PreviewKeyDown: Input
KeyDown: Input
KeyDown: Panel
KeyDown: RootGrid

This output illustrates the opposite directions of the preview and normal keyboard event routes.

Possible Output for a Handled Key

Enter text into the TextBox and then press the Left Arrow key. Depending on the control's state and handling behavior, the output may contain only the preview notifications:

PreviewKeyDown: RootGrid
PreviewKeyDown: Panel
PreviewKeyDown: Input

The absence of ordinary KeyDown notifications is consistent with the focused control consuming the input through its internal keyboard handling.

Testing limitation: These examples illustrate documented API behavior and the expected diagnostic results. They have not been independently compiled or executed as part of preparing this article. Verify the results using your project's Windows App SDK version and control configuration.

How to Intercept Keyboard Input Using PreviewKeyDown

When a container owns a particular keyboard operation, its preview handler can mark the event as handled to prevent subsequent normal processing of that input.

For example, suppose a Grid contains an application-specific overlay that should be dismissed when the user presses Escape.

Add the following event handler to the existing MainWindow implementation, with a matching declaration in the header file:

void MainWindow::Root_PreviewKeyDown(
    winrt::Windows::Foundation::IInspectable const& sender,
    winrt::Microsoft::UI::Xaml::Input::
        KeyRoutedEventArgs const& args)
{
    if (args.Key() !=
        winrt::Windows::System::VirtualKey::Escape)
    {
        return;
    }

    if (OverlayPanel().Visibility() ==
        winrt::Microsoft::UI::Xaml::Visibility::Visible)
    {
        OverlayPanel().Visibility(
            winrt::Microsoft::UI::Xaml::Visibility::Collapsed);

        args.Handled(true);
    }
}

This example requires an existing XAML element named OverlayPanel. Attach the handler to its appropriate ancestor using the PreviewKeyDown event. Ensure the focused element remains within that ancestor's event route.

The handler performs three operations:

  1. Checks whether the pressed key is Escape.
  2. Checks whether the application overlay is currently visible.
  3. Dismisses the overlay and marks the event as handled only when the operation is actually performed.

If the overlay is not visible, the handler leaves the input unchanged so normal keyboard processing can continue.

For a production overlay, also manage keyboard focus appropriately when the overlay closes. If the application uses a standard dialog or Flyout that already implements Escape handling, prefer the built-in behavior.

Understanding the Handled Property

The Handled property of KeyRoutedEventArgs communicates that the input has been processed and should not continue invoking ordinary handlers as though it were unhandled.

In C++/WinRT, the property is set using the following syntax:

args.Handled(true);

Its current value can be inspected using:

bool handled = args.Handled();

Developers should distinguish between observing keyboard input and consuming it.

  • Observing input: Read the key and other event information without changing the handled state.
  • Consuming input: Perform the intended operation and mark the event as handled when appropriate.

Do not routinely set the Handled property to true in a root-level preview handler. Doing so can unintentionally interfere with typing, keyboard shortcuts, focus navigation and accessibility.

Similarly, avoid resetting the property to false merely to force additional event processing. Earlier handling may represent an intentional operation performed by another component.

Receiving Keyboard Events That Have Already Been Handled

PreviewKeyDown is not the only mechanism available when an application needs to observe keyboard input that a control might consume.

The UIElement.AddHandler method can register a handler for an eligible routed event even when earlier processing has marked the event as handled.

The method accepts a parameter named handledEventsToo. Setting this parameter to true allows the registered handler to receive applicable handled routed events.

C++/WinRT AddHandler Example

The following registration can be placed in the MainWindow constructor after InitializeComponent():

RootGrid().AddHandler(
    winrt::Microsoft::UI::Xaml::UIElement::KeyDownEvent(),
    winrt::Microsoft::UI::Xaml::Input::KeyEventHandler{
        this,
        &MainWindow::OnObservedKeyDown
    },
    true);

Declare OnObservedKeyDown in the MainWindow header with the same signature as the earlier KeyDown handler, and implement it as follows:

void MainWindow::OnObservedKeyDown(
    winrt::Windows::Foundation::IInspectable const& sender,
    winrt::Microsoft::UI::Xaml::Input::
        KeyRoutedEventArgs const& args)
{
    if (args.Handled())
    {
        OutputDebugStringW(L"Handled KeyDown observed\n");
    }
    else
    {
        OutputDebugStringW(L"Unhandled KeyDown observed\n");
    }
}

This technique is useful for diagnostics and specialized event processing where a normal XAML event subscription is insufficient.

It applies only to events that expose a suitable routed event identifier. The KeyDownEvent and KeyUpEvent identifiers support this registration mechanism.

PreviewKeyDown vs. AddHandler

Characteristic PreviewKeyDown AddHandler with handledEventsToo
Processing stage Before normal focused-control processing At the registered element's normal routed-event stage
Routing strategy Tunneling Does not change the event's existing routing strategy
Primary purpose Early observation or interception Receiving eligible events despite previous handling
Can prevent earlier control behavior? Can intercept input before normal control processing Cannot retroactively prevent behavior already performed
Typical use Container-level input handling Diagnostics and specialized event observation

Use PreviewKeyDown when timing is important and the application must act before the focused control. Use AddHandler when the objective is to observe a supported routed event despite earlier handling.

Why Don't Other WinUI 3 Routed Events Have Preview Counterparts?

Developers familiar with routed keyboard events may expect similar tunneling counterparts for pointer, touch and other input events.

For example, WinUI 3 exposes pointer events such as:

  • PointerPressed
  • PointerReleased
  • PointerMoved
  • PointerWheelChanged

However, the standard UIElement API does not provide a matching tunneling PreviewPointerPressed event.

Documented Behavior

Microsoft's WinUI API reference identifies PreviewKeyDown and PreviewKeyUp as tunneling keyboard events and identifies their corresponding normal keyboard events.

The available routed-event documentation does not establish a general requirement that every bubbling input event must have a tunneling counterpart.

Practical Architectural Interpretation

Keyboard and pointer input use different targeting mechanisms.

Keyboard input generally targets the element with keyboard focus. Pointer input commonly targets an element identified through hit testing, although mechanisms such as pointer capture can affect event targeting.

Because focused controls frequently implement keyboard-specific behavior, early keyboard interception provides a useful mechanism for resolving conflicts between container-level operations and control-level keyboard processing.

For other input events, applications can use the mechanisms available for those event types, including normal event routing, pointer capture and eligible handled-event registrations.

These differences help explain why the existing API design is useful. They do not establish Microsoft's original engineering motivation for limiting the availability of tunneling input events.

Important: The distinction between keyboard and pointer input is a practical interpretation of the documented behavior, not an officially confirmed reason for Microsoft's framework design decision.

WinUI 3 vs. WPF Event Routing

Windows Presentation Foundation (WPF) and WinUI 3 are separate XAML-based user interface frameworks. Although they share many similar concepts, their event systems are not interchangeable.

WPF exposes routed input event pairs for a wider range of interactions, including keyboard and mouse input. It also provides a public routed-event registration model that supports different routing strategies.

WinUI 3 exposes specific routed events through its Windows App SDK APIs. Developers should use the routing behavior defined for each available event rather than assuming WPF event names or routing facilities exist in WinUI.

Feature WinUI 3 WPF
PreviewKeyDown Supported Supported
PreviewKeyUp Supported Supported
KeyDown and KeyUp Supported Supported
PreviewMouseDown No equivalent event under this name Supported
Primary pointer input abstraction Pointer events Mouse, stylus and touch events
Event-routing API Framework-provided routed event contracts Extensible routed-event infrastructure
Primary XAML namespace in code Microsoft.UI.Xaml System.Windows

When migrating a WPF application to WinUI 3, review each preview input handler individually and select the appropriate WinUI input-handling mechanism.

WinUI 3, UWP and API Namespace Compatibility

Similar keyboard event APIs are available in the Universal Windows Platform (UWP). However, WinUI 3 and UWP use different XAML namespaces.

Framework XAML Namespace Keyboard Event Argument Type
WinUI 3 Microsoft.UI.Xaml Microsoft.UI.Xaml.Input.KeyRoutedEventArgs
UWP Windows.UI.Xaml Windows.UI.Xaml.Input.KeyRoutedEventArgs
WPF System.Windows System.Windows.Input.KeyEventArgs

The C++/WinRT examples in this article target WinUI 3 and therefore use the Microsoft.UI.Xaml namespace for XAML types.

Microsoft's Windows App SDK API reference lists PreviewKeyDown across multiple SDK releases, including the 1.x product family. Consult the API reference corresponding to your project's installed SDK version for exact availability and signatures.

Do not copy UWP or WPF implementation examples directly into a WinUI 3 application without checking their namespaces, event argument types and framework-specific behavior.

When Should You Use Each Keyboard Handling Mechanism?

Requirement Recommended Mechanism
Execute logic before the focused control processes a key PreviewKeyDown
Inspect key release before normal release handling PreviewKeyUp
Respond to ordinary keyboard input KeyDown
Respond to ordinary key release KeyUp
Observe supported keyboard events already handled by a control AddHandler with handledEventsToo enabled
Implement standard application keyboard shortcuts KeyboardAccelerator
Respond to a change in TextBox content TextChanged
Validate a proposed TextBox content change BeforeTextChanging
Respond to pointer interaction Applicable pointer or higher-level control event

Troubleshooting Common Keyboard Event Problems

KeyDown Does Not Fire on the Parent Grid

A focused child control or an accelerator may have marked the input as handled.

First, determine whether the parent receives PreviewKeyDown for the same key. If it does, but the normal KeyDown handler is absent, investigate the focused control's built-in behavior.

Use PreviewKeyDown if early interception is necessary, or AddHandler with handledEventsToo enabled if the objective is to observe the handled event.

PreviewKeyDown Does Not Fire

Verify the following conditions:

  • The application window is active.
  • An appropriate element has keyboard focus.
  • The focused element is within the relevant event route.
  • The event handler is correctly declared and connected.
  • An earlier handler has not already consumed the preview event.
  • The key is not reserved or intercepted by Windows before reaching the application.

Be particularly careful with separate windows and popup-based UI. Their input routes may differ from the ordinary page hierarchy.

Keyboard Shortcuts Execute More Than Once

This problem can occur when the same operation is implemented in multiple keyboard handlers, accelerators or ancestor elements.

It can also occur because holding down a key generates repeated key-down notifications.

Centralize the operation in an appropriate handler and mark the input as handled when necessary. For operations intended to run only once per physical key press, investigate the key status information provided by the event arguments.

TextBox Stops Accepting Keyboard Input

A PreviewKeyDown handler may be marking too many events as handled.

Review all ancestor preview handlers and ensure that Handled(true) is called only for input that the application intentionally consumes.

Test ordinary typing, caret movement, text selection, editing shortcuts and keyboard focus navigation after making changes.

The Sender Is Not the Focused TextBox

In a routed event handler, the sender identifies the element whose handler is currently running.

For example, when the RootGrid handler executes, sender identifies RootGrid rather than necessarily identifying the focused TextBox.

The OriginalSource property can help identify the original event source. However, control templates may introduce internal elements, so OriginalSource should not automatically be treated as identical to a particular named control or the currently focused element.

Root-Level Handler Does Not Receive Every System Shortcut

PreviewKeyDown is a XAML routed event, not a system-wide keyboard hook.

Its scope is limited to keyboard input delivered through the applicable application UI route. It does not guarantee access to operating-system-reserved shortcuts or input directed to another application.

This is expected behavior and does not indicate a problem with tunneling.

Documentation Inconsistency Regarding Preview Event Routing

Developers researching this topic may encounter inconsistent terminology in Microsoft's keyboard accelerator documentation.

The advanced keyboard accelerator discussion contains wording that can suggest preview events participate in bubbling. However, the individual PreviewKeyDown API reference explicitly specifies tunneling as its routing strategy.

When determining an individual event's routing direction, prioritize its specific API contract and verify behavior with a controlled diagnostic example when necessary.

The keyboard accelerator documentation remains useful for understanding processing priority, accelerator behavior and the relationship between preview events and normal keyboard handling. Its description should not be interpreted as overriding the event-specific routing contract.

Best Practices for Keyboard Event Handling

  • Prefer native control behavior: Preserve built-in keyboard interactions whenever possible.
  • Use keyboard accelerators for commands: Prefer KeyboardAccelerator for standard application shortcuts instead of manually implementing every command through preview events.
  • Restrict interception scope: Attach preview handlers to the most appropriate container rather than automatically placing all keyboard logic at the root.
  • Consume only relevant input: Set Handled to true only when the application has intentionally processed or suppressed the operation.
  • Avoid duplicate handling: Do not execute the same application command through multiple event-processing mechanisms without coordination.
  • Preserve accessibility: Test Tab navigation, Shift+Tab navigation, standard shortcuts and assistive technology compatibility.
  • Keep handlers efficient: Avoid lengthy synchronous operations inside keyboard handlers.
  • Use text-specific events for validation: Do not rely exclusively on keyboard events to validate text because content may also change through paste, touch input, input method editors or programmatic updates.
  • Verify SDK-specific behavior: Test keyboard interactions against the Windows App SDK version distributed with your application.
  • Avoid logging sensitive input: Do not record passwords, confidential text or unnecessary user keystrokes in production diagnostic logs.

Frequently Asked Questions

Is PreviewKeyDown a Bubbling or Tunneling Event in WinUI 3?

PreviewKeyDown is a tunneling event. Its corresponding bubbling event is KeyDown, as specified by the Windows App SDK API reference.

Is PreviewKeyUp Also a Tunneling Event?

Yes. PreviewKeyUp provides the preview phase for keyboard key release. Its corresponding normal bubbling event is KeyUp.

Does Every Event Beginning with Preview Use Tunneling?

No. An event's name alone does not establish its routing strategy. Developers should consult the documentation for the specific event and framework.

Can PreviewKeyDown Prevent a TextBox from Processing a Key?

Yes. Appropriately marking keyboard input as handled during the preview phase can suppress subsequent normal control processing. This capability should be used selectively to avoid interfering with editing and navigation.

Does Handling PreviewKeyDown Automatically Handle KeyUp?

No. Key press and key release processing are distinct. Handling the key-down input does not automatically mean that the corresponding key-up input will also be handled.

Can AddHandler Change a Bubbling Event into a Tunneling Event?

No. AddHandler changes how a handler is registered and can allow observation of eligible handled events. It does not change the routing direction of the event.

Is PreviewKeyDown Available Directly on a WinUI 3 Window?

The PreviewKeyDown event is provided by UIElement. For window-content keyboard handling, attach the event to an appropriate root Grid, Page or other UIElement within the Window's content rather than assuming the Window itself exposes the same routed event.

Can PreviewKeyDown Be Used for Application-Wide Keyboard Shortcuts?

It can support shortcuts within an applicable XAML event route. However, KeyboardAccelerator is generally the more appropriate mechanism for standard application commands. A root-level preview handler is not automatically shared across every window or independent UI tree.

Is Keyboard Event Routing Different Between C# and C++/WinRT?

The underlying WinUI routing behavior is the same. The main differences concern language syntax, event registration and type projections rather than the direction of the routed events.

Is the Observed Tunneling Behavior a WinUI 3 Bug?

No. PreviewKeyDown traveling toward the focused element, followed by KeyDown traveling toward ancestor elements when eligible, is consistent with the documented routing strategies.

Key Takeaways

  • PreviewKeyDown and PreviewKeyUp provide tunneling keyboard event routes.
  • KeyDown and KeyUp provide bubbling keyboard event routes.
  • Preview events allow ancestor elements to inspect keyboard input before normal focused-control handling.
  • Controls and keyboard accelerators can consume input and suppress ordinary routed-event handlers.
  • AddHandler provides an alternative mechanism for receiving eligible events that have already been handled.
  • WinUI 3 and WPF expose different routed-event APIs and should not be treated as interchangeable frameworks.
  • The exact architectural rationale for limiting equivalent tunneling counterparts is not established by the Microsoft documentation reviewed for this article.

Choose the keyboard input mechanism according to the required processing stage. Use preview events for necessary early interception, ordinary keyboard events for normal input handling, and keyboard accelerators for application commands.

Official Microsoft References

YOUR FEEDBACK

Was this guide useful?

Your answer helps us keep BISONKB accurate and practical.

Links are permitted only to published BISONKB articles.