Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyDown Bubbling Event Not Triggered After Navigation and Focus Gain #1268

Open
keeleycenc opened this issue Nov 7, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@keeleycenc
Copy link

Describe the bug

After navigating to any interface and once the interface gains focus, I've noticed that the KeyDown event (a bubbling event) often fails to trigger. This issue primarily affects the arrow keys: Up, Down, Left, and Right. I suspect this may be due to the PreviewKeyDown event (a tunneling event) being handled prematurely, which prevents the bubbling KeyDown event from being properly triggered.

To Reproduce

Steps to Reproduce

Step 1: Add tunneling and bubbling key event subscriptions in the main window constructor:

    public MainWindow(
        MainWindowViewModel viewModel,
        INavigationService navigationService,
        IServiceProvider serviceProvider,
        ISnackbarService snackbarService,
        IContentDialogService contentDialogService
    )
    {
        Appearance.SystemThemeWatcher.Watch(this);

        ViewModel = viewModel;
        DataContext = this;

        InitializeComponent();

        snackbarService.SetSnackbarPresenter(SnackbarPresenter);
        navigationService.SetNavigationControl(NavigationView);
        contentDialogService.SetDialogHost(RootContentDialog);

        PreviewKeyDown += OnPreviewKeyDown;
        KeyDown += OnKeyDown;
    }
    

        private void OnKeyDown(object sender, KeyEventArgs e)
    {
        Debug.WriteLine($"OnKeyDown {e.Key}");
    }

    private void OnPreviewKeyDown(object sender, KeyEventArgs e)
    {
        Debug.WriteLine($"OnPreviewKeyDown {e.Key}");
    }

Step 2: Start the application and without performing any actions, test key presses. The output is as follows:

21:05:06:923	OnPreviewKeyDown Up
21:05:06:923	OnKeyDown Up
21:05:07:169	OnPreviewKeyDown Down
21:05:07:169	OnKeyDown Down
21:05:07:416	OnPreviewKeyDown Left
21:05:07:416	OnKeyDown Left
21:05:07:416	OnPreviewKeyDown Right
21:05:07:416	OnKeyDown Right

Step 3: Click any menu item in the navigation bar (e.g., Base Input) so that the focus moves to the navigation bar. Press the keys again and observe the output:

21:08:04:890	OnPreviewKeyDown Up
21:08:05:639	OnPreviewKeyDown Down
21:08:05:889	OnPreviewKeyDown Left
21:08:06:141	OnPreviewKeyDown Right

Step 4: Click on the first gallery navigation item Anchor and press the keys again. The output is as follows:

21:11:16:533	OnPreviewKeyDown Up
21:11:16:533	OnKeyDown Up
21:11:16:777	OnPreviewKeyDown Down
21:11:16:777	OnKeyDown Down
21:11:16:777	OnPreviewKeyDown Left
21:11:16:777	OnKeyDown Left
21:11:17:029	OnPreviewKeyDown Right
21:11:17:029	OnKeyDown Right

Step 5 (Critical Step): Click any element on this page to gain focus (e.g., expand the source code), then press the keys again. The output is as follows:

21:12:57:145	OnPreviewKeyDown Up
21:12:57:391	OnPreviewKeyDown Down
21:12:57:391	OnPreviewKeyDown Left
21:12:57:637	OnPreviewKeyDown Right

However, other keys can still trigger the bubbling event:

21:14:23:389	OnPreviewKeyDown Up
21:14:23:639	OnPreviewKeyDown Down
21:14:23:889	OnPreviewKeyDown Left
21:14:23:889	OnPreviewKeyDown Right
21:14:25:640	OnPreviewKeyDown A
21:14:25:640	OnKeyDown A
21:14:26:387	OnPreviewKeyDown B
21:14:26:387	OnKeyDown B
21:14:26:639	OnPreviewKeyDown C
21:14:26:639	OnKeyDown C

Expected behavior

Please avoid handling key events directly in the tunneling event, as this can prevent text editors on the page from properly handling cursor movement and can also disrupt key event propagation for the WebView2 control. This behavior may negatively impact keyboard-based user interactions and reduce overall user experience.

Moreover, when I created a new window and moved the page content to this new window, the text editor’s cursor movement function worked correctly, and the WebView2 control could receive key events. This proves that the previously described issue does not occur in the new window, confirming that the bug originates from the navigation bar.

Screenshots

No response

OS version

Edition: Windows 11 Pro
Version: 23H2
Installation Date: ‎February 29, 2024
OS Build: 22631.4317
Experience: Windows Feature Experience Pack 1000.22700.1041.0

.NET version

.NET 8.0

WPF-UI NuGet version

Version: 3.0.5, and the testing was conducted using the source code repository cloned two days ago, with the same issue observed.

Additional context

It should not be related to <ui:NavigationView.AutoSuggestBox>, as it was removed and tested without it.

@keeleycenc keeleycenc added the bug Something isn't working label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant