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!
–
–
–
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.
–
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.