【发布时间】:2019-02-25 17:54:00
【问题描述】:
我正在尝试根据内容动态缩放第二行,但它应该只增长到某个高度。与聊天应用程序所做的类似,expandable editor 会根据其包含的文本进行扩展。我的问题是,如果文本真的足够高,它可能会使第一行不可见。
如何设置第二行的最大高度,以免第一行被遮挡?
ContentPage.cs
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:renderer="clr-namespace:Project.renderers"
x:Class="Project.MainPage">
<Grid VerticalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ListView VerticalOptions="Fill" Grid.Row="0"/>
<StackLayout Orientation="Horizontal"
VerticalOptions="EndAndExpand"
BackgroundColor="Green"
HorizontalOptions="Fill"
Grid.Row="1">
<renderer:ExpandableEditor VerticalOptions="FillAndExpand"
HorizontalOptions="Center"
MaxLength="3000"
AutoSize="TextChanges"
TextColor="Black"/>
</StackLayout>
</Grid>
</ContentPage>
ExpandableEditor.cs
public class ExpandableEditor : Editor
{
public ExpandableEditor()
{
TextChanged += OnTextChanged;
}
~ExpandableEditor()
{
TextChanged -= OnTextChanged;
}
private void OnTextChanged(object sender, TextChangedEventArgs e)
{
InvalidateMeasure();
}
}
【问题讨论】:
标签: c# xaml xamarin.forms