You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Maui Frame如何设置定位到屏幕底部?

让.NET Maui中的Frame定位到屏幕底部的方法

你可以通过调整布局结构或控件属性来实现,以下是两种常用方案:

方案一:使用Grid布局(推荐,适合页面包含其他内容的场景)

通过给Grid定义行,让Frame占据底部的自适应行:

<Grid>
    <!-- 定义两行:第一行占满剩余空间,第二行自适应Frame高度 -->
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <!-- 这里放置页面的其他内容(比如聊天消息列表) -->

    <Frame BorderColor="#2f3136"
           CornerRadius="20"
           BackgroundColor="#2f212b"
           Grid.Row="1"> <!-- 将Frame放在第二行(底部行) -->
        
        <Editor x:Name="inputBox" 
                Placeholder="Enter your message (2000 characters max)"
                TextChanged="inputBox_Changed"
                Completed="inputBox_Completed"
                MaxLength="2000"
                Keyboard="Chat"
                AutoSize="TextChanges"/>
    
    </Frame>
</Grid>

方案二:设置VerticalOptions属性(适合简单布局)

如果Frame的父布局是VerticalStackLayout或其他支持布局选项的容器,直接给Frame添加VerticalOptions="End"属性即可:

<VerticalStackLayout>
    <!-- 页面其他内容 -->

    <Frame BorderColor="#2f3136"
           CornerRadius="20"
           BackgroundColor="#2f212b"
           VerticalOptions="End">
        
        <Editor x:Name="inputBox" 
                Placeholder="Enter your message (2000 characters max)"
                TextChanged="inputBox_Changed"
                Completed="inputBox_Completed"
                MaxLength="2000"
                Keyboard="Chat"
                AutoSize="TextChanges"/>
    
    </Frame>
</VerticalStackLayout>

补充说明

你原来的Frame显示在顶部,是因为默认布局选项VerticalOptions="Start",且Grid.Row="0"在只有一行的Grid中会占据顶部位置。上述两种方法分别通过布局结构调整或属性设置,让Frame固定在屏幕底部。

内容的提问来源于stack exchange,提问作者smol

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 19:30:48