Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for DONE button to keyboard in .NET MAUI
Victor Hugo Garcia
Victor Hugo Garcia

Posted on • Edited on

     

DONE button to keyboard in .NET MAUI

In this article, I'm going to show you how to add a DONE button to the keyboard in .NET MAUI by using a custom handler foriOS compatible with iOS 15+.


Create a static class EntryHandler

usingMicrosoft.Maui;usingSystem.Drawing;#if IOSusingUIKit;usingFoundation;#endifnamespaceDemoMauiApp.Handlers;publicclassEntryHandler{publicstaticvoidAddDone(){Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping("Done",(handler,view)=>{#if IOSvartoolbar=newUIToolbar(newRectangleF(0.0f,0.0f,50.0f,44.0f));toolbar.BackgroundColor=UIColor.LightGray;// Set the color you prefervardoneButton=newUIBarButtonItem(UIBarButtonSystemItem.Done,delegate{handler.PlatformView.ResignFirstResponder();});toolbar.Items=newUIBarButtonItem[]{newUIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),doneButton};handler.PlatformView.InputAccessoryView=toolbar;#endif});}}
Enter fullscreen modeExit fullscreen mode

Register the handler

On theMauiProgram.cs file register the handler
EntryHandler.AddDone();

Conclusion

This is a port from our friendyuv4ik atgithub(thanks for sharing it) with a few modifications to add the DONE button to all types of keyboards in .NET MAUI using handlers.

Thanks for reading! Follow me on Twitter@ivictorhugo

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
marklindsay99 profile image
marklindsay99
  • Joined

this was very helpful!

CollapseExpand
 
smkms profile image
Sameer
  • Joined

Completed event in the entry can be triggered with following slight modification incase logic is dependent on Completed event:

var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, delegate
{
handler.PlatformView.ResignFirstResponder();
handler.VirtualView?.Completed(); // <--- Triggers completed event
});

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Passionate software engineer with a love for design and an unwavering commitment to enjoying life to the fullest.
  • Location
    Austin, Texas
  • Education
    Instituto Tecnológico de Ciudad Guzman
  • Work
    Software Engineer at simplea.com
  • Joined

More fromVictor Hugo Garcia

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp