设置RowDefinition可以采用Xamarin App的最大高度

时间:2019-02-25 00:58:11

标签: c# xaml xamarin.forms

我正在尝试根据内容动态地缩放第二行,但是它只能增长到一定高度。与聊天应用程序正在执行的操作类似,expandable editor会根据其包含的文本进行扩展。我的问题是,如果文本足够高,可能会使第一行不可见。

如何设置第二行的最大高度,以免遮挡第一行?

ContentPage.cs

import timeit, random


list_of_tuples = [('here is some text', 1), ('this is more text', 5), ('a final tuple', 12)]
big_list = [random.choice(list_of_tuples) for x in range(1000)]


def gen(lot=big_list, m='tokenize'):
    list_all_words = []
    tokenised_words = []
    i1 = 0
    i2 = 0
    i3 = 0
    lol1 = len(lot)
    while i1 < lol1:
        # yield lot[i1]
        lol2 = len(lot[i1])
        while i2 < lol2:
            if type(lot[i1][i2]) == str:
                list_all_words.append((lot[i1][i2].split(), i1 + 1))
            i2 += 1
        i1 += 1
        i2 = 0
    # print(list_all_words)
    lol3 = len(list_all_words)
    while i3 < lol3:
        tokenised_words += list_all_words[i3][0]
        i3 += 1
    if m == 'list':
        yield list_all_words
    if m == 'tokenize':
        yield tokenised_words


for x in gen():
    print(x)


print(timeit.timeit(gen))
# Output of timeit: 0.2610903770813007
# This should be unnoticable on system resources I would have thought.

ExpandableEditor.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>

1 个答案:

答案 0 :(得分:0)

您不能为RowDefinition设置MaximumHeight。您应该为放置在行中的VisualElement设置最大高度。您可以使用MinimumHeightRequest属性来完成此操作。

注意:MinimumHeightRequest将在您请求的高度和您请求的最小高度之间选择最小值。 (Source

**更新**

A similar question是3年前在StackOverflow中被问到的。