添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
重感情的墨镜  ·  Spring Data ...·  1 年前    · 
强悍的台灯  ·  python - TensorFlow - ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to get a .NET Maui app up and running and it is working quite well so far - with one major problem: I cannot get it fixed that an Entry / Editor control stays above the keyboard and doesn't get overlapped.

I know there is an open issue and it is in the backlog, but the app seems unusable until this is fixed. There have been a couple of workarounds like

[GitHub] dotnet/maui issue 4792 ,
[GitHub] dotnet/maui issue 10662 (#1) and
[GitHub] dotnet/maui issue 10662 (#2)

but I cannot get them to work when registering as a handler. #1 doesn't do anything and #2 crashes when loading any view.

There is a solution on StackOverflow as well ( Question 72536074 ) - unfortunately this method ignores the keyboard height.

To reproduce the problem the simplest code example would be any ContentPage with the following content:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="EntryIssueMaui.MainPage">
    <ScrollView>
        <Entry VerticalOptions="End" BackgroundColor="LightCoral" /> 
    </ScrollView>
</ContentPage>

based on the default Maui template app.

It results in the Entry (red) not being pushed up in the ScrollView when the keyboard is enabled:

How can I implement the - I guess usually default feature - that the control is being pushed up to be still visible while considering the height of the keyboard (e.g. with/without autocompletion or emoji keyboard)?

Thanks in advance!

"unfortunately this method ignores the keyboard height." - First, you might need to test on actual device, not emulator. The Mac keyboard sometimes confuses the emulator's soft keyboard logic. Second, the "fallback" is to use the maximum keyboard height. I havent tested on Maui, but on Xamarin.Forms, I use technique that moves the page up enough to uncover all bottom-half entries (when clicking on an entry on the bottom half). For that, it doesn't matter whether one moves somewhat too far. The important point is to make sure the current entry is somewhere (anywhere) in the visible area. – ToolmakerSteve Feb 1 at 0:04 Since it uses "layout.TranslateTo(0, -200, 50);" with a fixed number, I am pretty sure it does not take the keyboard height into account - neither on the emulator nor on the physical device. Of course it is the important point, but I would love to make a clean solution as I am trying to improve my skillset by knowledge ;) – Niko Klemm Feb 1 at 0:25 I understand. You'll have to do a custom handler for iOS, as you mention attempting. If you want to pursue that, post the (not working) handler code. – ToolmakerSteve Feb 1 at 1:46

To solve this issue, you could obtain keyboard's frame via UIKeyboard.FrameEndUserInfoKey and calculate the height need to change.

NSValue result = (NSValue)args.Notification.UserInfo.ObjectForKey(new NSString(UIKeyboard.FrameEndUserInfoKey));
CGSize keyboardSize = result.RectangleFValue.Size;
private void Entry_Focused(object sender, FocusEventArgs e)
    if (DeviceInfo.Current.Platform == DevicePlatform.iOS)
       NFloat bottom;
             UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow();
                bottom = window.SafeAreaInsets.Bottom;
        catch
             bottom = 0;
        var heightChange = (keyboardSize.Height - bottom);
        layout.TranslateTo(0, originalTranslationY.Value - heightChange, 50);
private void Entry_Unfocused(object sender, FocusEventArgs e)
    if (DeviceInfo.Current.Platform == DevicePlatform.iOS)
        layout.TranslateTo(0, 0, 50);

Hope it works for you.

I've described my approach here using a custom control and handler: https://stackoverflow.com/a/75782242/250164

But it's a very basic example, e.g. it doesn't take into account the tab bar.

Solution for iOS keyboad overlap issue, that worked for me. Credit to author : github.com/massijay/iOSMauiScrollUpOnKeyboardShow/blob/main/… – Suchith Apr 17 at 17:58

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.