Soft Keyboard Open and Closed Events Detection in .Net Maui

dg2k 1,386 Reputation points
2022-09-23T06:24:26.297+00:00

While Soft Keyboard is the most basic part of UI programming, I found no easy way of detecting when the keyboard pops up, closes, or when it occludes other visual elements. That is Xamarin and before it.

Now with the new kid on the block, called Maui, I'm hoping that perhaps things will get better, and should get better.

Are there Soft Keyboard events, methods and properties that simplify programming?

As a starter, I would like to detect when the Soft Keyboard pops up. How can I do this in the cross-platform scenario?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,841 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 25,996 Reputation points Microsoft Vendor
    2022-09-26T10:03:15.87+00:00

    Hello,

    You have to detect the Soft Keyboard that pops up on each platform, you can try to invoke platform code or create a custom control using handlers.

    For iOS and MacCatalyst, you can use NSNotificationCenter to register a listener for DidHideNotification and DidShowNotification, please check the Remarks section to see the usage.

    For Android, you can try to get InputMethodManager.IsActive Property, :

    var IMS = MainActivity.instance.GetSystemService(Context.InputMethodService) as InputMethodManager;// add  public static MainActivity instance; in MainActivity  
    

    For Windows, you can refer to Keyboard events - Windows apps | Microsoft Learn.
    Note: Some docs are in Xamarin , you could try to implement a MAUI version.

    In addition, you could report the feature request at https://github.com/dotnet/maui
    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful