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

.NET MAUI Mac Catalyst中Editor控件滚动功能失效问题求助

解决.NET MAUI Editor控件滚动/自适应问题

方案1:让Editor自动随文本高度扩展(无需滚动)

把Editor的AutoSize改成Vertical或TextChanges,同时调整容器布局约束,确保有足够空间扩展:

<Frame x:Name="F_MessaggioDaInviare"
       Grid.Column="0"
       Margin="0"
       Padding="5"
       BackgroundColor="LightGreen"
       BorderColor="#3CB371"
       CornerRadius="5"
       HasShadow="False"
       VerticalOptions="Start"> <!-- 改为Start,避免强制填充父容器导致无法扩展 -->

    <Editor x:Name="E_MessaggioDaInviare"
            AutoSize="Vertical" <!-- 关键:启用垂直自动调整 -->
            MaxLength="1000"
            Margin="5,0,0,0"
            BackgroundColor="#3CB371"
            TextColor="LightGreen"
            FontSize="14"
            IsTextPredictionEnabled="False"
            FontAutoScalingEnabled="False"
            TextChanged="E_MessaggioDaInviare_TextChanged" />
</Frame>

注意:如果父容器(比如Grid的行)是固定高度,Editor也没法扩展,要确保父布局的行定义是Auto或者*。

方案2:固定高度+滚动(含自动滚到底部)

如果需要固定Editor高度并支持滚动,正确嵌套ScrollView,并在文本变化时手动滚动到底部:

<Frame x:Name="F_MessaggioDaInviare"
       Grid.Column="0"
       Margin="0"
       Padding="5"
       BackgroundColor="LightGreen"
       BorderColor="#3CB371"
       CornerRadius="5"
       HasShadow="False"
       VerticalOptions="Fill">

    <ScrollView HeightRequest="200" <!-- 固定滚动区域高度 -->
                VerticalScrollBarVisibility="Always">
        <Editor x:Name="E_MessaggioDaInviare"
                AutoSize="Disabled"
                MaxLength="1000"
                Margin="5,0,0,0"
                BackgroundColor="#3CB371"
                TextColor="LightGreen"
                FontSize="14"
                IsTextPredictionEnabled="False"
                FontAutoScalingEnabled="False"
                TextChanged="E_MessaggioDaInviare_TextChanged" />
    </ScrollView>
</Frame>

在后台代码的TextChanged事件中添加自动滚动逻辑:

private void E_MessaggioDaInviare_TextChanged(object sender, TextChangedEventArgs e)
{
    if (sender is Editor editor && editor.Parent is ScrollView scrollView)
    {
        // 延迟滚动确保文本渲染完成
        Device.BeginInvokeOnMainThread(() =>
        {
            scrollView.ScrollToAsync(0, scrollView.ContentSize.Height, false);
        });
    }
}

方案3:排查HeightRequest无效问题

如果设置HeightRequest没效果,检查以下几点:

  • Editor的父容器是否强制限制了高度(比如Frame的VerticalOptions为Fill,而父Grid行是固定高度)
  • 有没有其他布局控件(如StackLayout)的Spacing或Padding占用了可用空间
  • 尝试给Editor加上VerticalOptions="FillAndExpand",确保它能填满分配的空间

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 19:08:25