C# .NET MAUI - 当编辑器键盘弹出 .NET 7 时,页面布局无法正确调整大小。适用于 6

问题描述 投票:0回答:1

有人知道这里发生了什么吗?这适用于 .NET 6 但不适用于 7

public partial class App : Application
{
    public App ( )
    {
        InitializeComponent ( );

        BoxView box = new BoxView { Color = Colors.LightBlue } ;

        VerticalStackLayout layout = new VerticalStackLayout ( ) ;
        ScrollView scroll = new ScrollView { Orientation = ScrollOrientation.Vertical , Content = layout } ;

        for ( int i = 0 ; i < 20 ; i++ )
        {
            layout.Add ( new BoxView { Color = Colors.Wheat , HeightRequest = 75 } );
            layout.Add ( new BoxView { Color = Colors.LightCyan , HeightRequest = 75 } );
        }

        Editor editor = new Editor { BackgroundColor = Colors.Green } ;

        Grid grid = new Grid ( ) ;

        grid.AddRowDefinition ( new RowDefinition { Height = 100 } );
        grid.AddRowDefinition ( new RowDefinition { Height = new GridLength ( 1 , GridUnitType.Star ) } );
        grid.AddRowDefinition ( new RowDefinition { Height = 100 } );

        grid.Add ( box , 0 , 0 );
        grid.Add ( scroll , 0 , 1 );
        grid.Add ( editor , 0 , 2 );

        MainPage = new ContentPage { Content = grid };
    }
}

使用 .NET 7 我正在尝试以编程方式向 MainPage 添加一个编辑器,并在弹出键盘时正确调整布局。目前,键盘上方的整个页面向上滑动与键盘相同的高度,而该页面应该压缩在中间网格 .STAR 元素中。适用于 .NET 6

c# editor maui
1个回答
0
投票

您可以将 WindowSoftInputModeAdjust 附加属性设置为 Resize。试试下面的代码:

<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:android="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;assembly=Microsoft.Maui.Controls"
         android:Application.WindowSoftInputModeAdjust="Resize"
         ...>
    <Application.Resources>
    ....
    </Application.Resources>
</Application>

更多信息,您可以参考Android上的软键盘输入模式

© www.soinside.com 2019 - 2024. All rights reserved.