MAUI 横向模式网格问题

问题描述 投票:0回答:1
grid maui landscape
1个回答
0
投票

我复制了您的代码,只需为网格添加

Grid.RowSpan="3"
即可。然后我就得到了你想要的效果,没有
LayoutChanged
Appearing

完整的xaml:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp7.MainPage" Shell.NavBarIsVisible="False">

    <Grid BackgroundColor="Pink">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="80" />
            <ColumnDefinition Width="80"/>
            <ColumnDefinition Width="80"/>
            <ColumnDefinition Width="80"/>
            <ColumnDefinition Width="80"/>
            <ColumnDefinition Width="80"/>
            <ColumnDefinition Width="*"/>

        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="80"/>
            <RowDefinition Height="80"/>
            <RowDefinition Height="80"/>
        </Grid.RowDefinitions>
        <Grid x:Name="gridLayoutBox" 
              BackgroundColor="Blue"  
              IsClippedToBounds="True" 
              Grid.ColumnSpan="6" 
              Grid.RowSpan="3" >

        </Grid>
    </Grid>
</ContentPage>

结果图像:

另外,如果想强制横向,可以将以下代码全部放在Page的OnHandlerChanged方法或者OnAppearing方法中。

#if ANDROID
Microsoft.Maui.ApplicationModel.Platform.CurrentActivity.RequestedOrientation = Android.Content.PM.ScreenOrientation.Landscape;
#endif

在人像模式下,蓝色网格会被剪掉,因为它的宽度大于屏幕的宽度。

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