【问题标题】:Maui XAML: Elements are positioned at top and buttom of vertical stack layoutMaui XAML:元素位于垂直堆栈布局的顶部和底部
【发布时间】:2022-12-11 05:14:42
【问题描述】:

多年来我一直在使用 xamarin,我知道这段代码应该有效:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Skillbased.Pages.LogIn.CreateAccount.Page_Tutorial"
             Title="Page_Tutorial">
    <ScrollView>
        <StackLayout>
            <Grid Margin="0,30,0,0">        
                <Image Source="img_headerbar"/>
                 <Label VerticalOptions="Center"
                       FontFamily="BebasNeue"
                       FontSize="30"
                       HorizontalOptions="Center"
                       Text="WARUM SKILLBASED?"/>
            </Grid>
            <Image VerticalOptions="Start" Source="img_bike"/>
        </StackLayout>
    </ScrollView>
</ContentPage>

但结果是这样的:

不,底部的图片顶部没有大的空白区域。

我什至用网格试过了,但它仍然位于底部。这里到底发生了什么?

编辑:

哦,如果我尝试在 android 上部署:

.. 事情解决了,但是关闭了,这里的字体不能在 android 上正确加载......不管怎样,问题似乎是为什么 maui

【问题讨论】:

  • 是的,我在最外面做了网格,我也做了 verticalstacklayout。两者都不起作用,而且这个问题只出现在 ios 上(正如你在我的编辑中看到的那样)。其他未满屏的图片也不存在此问题
  • 抱歉,我在您编辑后删除了我的评论,因为它不再适用了。

标签: xaml maui


【解决方案1】:

我相信您需要将 Grid 完全放在外面并将 ScrollView 放在里面。然后使用 VerticalStackLayout 并将其定位在 Start(.NET MAUI 中不再存在 Xamarin.Forms 中的“展开”选项).

这对你有用吗?

<Grid>
  <ScrollView>
    <VerticalStackLayout
      Spacing="0"
      Margin="0"
      VerticalOptions="Start">

      <Grid Margin="0,30,0,0"
            VerticalOptions="Start">
        <Image Source="img_headerbar"/>
        <Label VerticalOptions="Center"
               FontFamily="BebasNeue"
               FontSize="30"
               HorizontalOptions="Center"
               Text="WARUM SKILLBASED?"/>
      </Grid>
      <Image VerticalOptions="Start" Source="img_bike"/>

    </VerticalStackLayout>
  </ScrollView>
</Grid>

【讨论】:

  • 谢谢,但结果是 100% 相同的。 ios上的图片呈现在底部。如果我使用另一张不完整的图片,它可以工作,但那是别无选择
  • 您是否已在 MAUI 的 GitHub 存储库中搜索过此问题? github.com/dotnet/maui/issues
  • 是的,我经历过这个,这还没有提出来。无论如何,我已经决定创建一些票,因为有很多问题(标签上的 linehuight 被破坏,自定义字体没有加载,这个问题在这里......)
【解决方案2】:

尝试在 StartAndExpand 上设置 VerticalOrientation 属性。图像是否移动或是否将其设置为中心?

我还会将两个图像的背景设置为红色或其他颜色。有了这个,您可以查看 iOS 是否可以扩展它们。

我最后的想法是设置 Grid.RowDefinition。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-11
    • 2018-08-09
    • 2015-03-31
    • 2021-04-26
    相关资源
    最近更新 更多