question

dg2k avatar image
0 Votes"
dg2k asked WenyanZhang-MSFT edited

Soft Keyboard Open and Closed Events Detection in .Net Maui

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?

dotnet-maui
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

WenyanZhang-MSFT avatar image
0 Votes"
WenyanZhang-MSFT answered WenyanZhang-MSFT edited

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.