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

[WIN] MAUI Not Returning and Sending Microsoft.UI.Xaml.Input.PreviewKeyDown Event When Subscribed. #23789

Open
cgp1976 opened this issue Jul 24, 2024 · 4 comments
Labels
area-xaml XAML, CSS, Triggers, Behaviors platform/windows 🪟 s/needs-info Issue needs more info from the author s/no-recent-activity Issue has had no recent activity s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@cgp1976
Copy link

cgp1976 commented Jul 24, 2024

Description

There are two issues here

  1. MAUI Not Returning Microsoft.UI.Xaml.Input.PreviewKeyDown Event When Subscribed.
  2. MAUI Stop Sending Microsoft.UI.Xaml.Input.PreviewKeyDown Event When Subscribed.
var platformView = this.Handler.PlatformView as Microsoft.Maui.Platform.ContentPanel;
platformView.PreviewKeyDown += PlatformView_PreviewKeyDown;

private void PlatformView_PreviewKeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
{
    Debug.WriteLine($"Invoked @ {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}");
}

For Point 1
if the entire layout doesn't have a button control. this will never trigger the event.

For Point 2
We put a button control in the grid and from there onwards, we are able to receive the event but for some reasons, this will only work two times after it successfully invoked.

Steps to Reproduce

MauiApp1.zip

Unzipped the attached file

For Point 1
Go to MainPage.xaml and replace the entire Grid xaml with the following

    <Grid BackgroundColor="Gray">
        <Label BackgroundColor="Pink" Text="Label" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" HeightRequest="30" WidthRequest="100"></Label>
    </Grid>

Run and Debug the project , once page loaded, you can input some keyboard input to see if event was invoked or not.
Expected - PlatformView_PreviewKeyDown is never called

For Point 2
Go to MainPage.xaml and replace the entire Grid xaml with the following

    <Grid BackgroundColor="Gray">
        <Button Text="Button" BackgroundColor="Blue" HeightRequest="30" WidthRequest="100"></Button>
    </Grid>

Run and Debug the project , once page loaded, you can input some keyboard input to see if event was invoked or not.
Expected - PlatformView_PreviewKeyDown was Invoked, and it will fail after two times

Link to public reproduction project repository

No response

Version with bug

9.0.0-preview.6.24327.7

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

No response

Did you find any workaround?

nil

Relevant log output

No response

@cgp1976 cgp1976 added the t/bug Something isn't working label Jul 24, 2024
Copy link
Contributor

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@kevinxufei kevinxufei added platform/windows 🪟 s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 24, 2024
@Foda
Copy link
Member

Foda commented Aug 19, 2024

I've verified that this also doesn't work with NET8 versions, but I don't think it's a bug. I suspect that the preview key down events only trigger when a control has focus (ie: the button).

If your goal is to invoke commands, keyboard accelerators might be a solution: https://learn.microsoft.com/en-us/dotnet/maui/user-interface/keyboard-accelerators

@samhouts samhouts added the area-xaml XAML, CSS, Triggers, Behaviors label Aug 28, 2024
@jsuarezruiz jsuarezruiz added the s/needs-info Issue needs more info from the author label Oct 15, 2024
Copy link
Contributor

Hi @cgp1976. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@dotnet-policy-service dotnet-policy-service bot added the s/no-recent-activity Issue has had no recent activity label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-xaml XAML, CSS, Triggers, Behaviors platform/windows 🪟 s/needs-info Issue needs more info from the author s/no-recent-activity Issue has had no recent activity s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants