TextWrapped Label在StackLayout中打破布局选项FillAndExpand

时间:2016-12-23 10:27:43

标签: xamarin xamarin.forms textwrapping

我有一个带有嵌套StackLayout s的单元格视图,如果文本很长,那么会有一个标签被包装,这是所需的行为。但是,换行会将LayoutOptions设置为(基本上)所有父视图,导致右侧出现灰色间隙。

    <StackLayout Orientation="Horizontal" BackgroundColor="Gray" Margin="0,30,0,0">
        <BoxView
            HorizontalOptions="Start"
            BackgroundColor="#EEBB00"
            WidthRequest="100"
        />
        <StackLayout
            BackgroundColor="#CC4400"
            HorizontalOptions="FillAndExpand"
        >
            <BoxView
                BackgroundColor="Green"
                HeightRequest="10"
                HorizontalOptions="FillAndExpand"
            />
            <Label
                FontSize="16"
                HorizontalOptions="FillAndExpand"
                Text="Name that is toolongandwillbewrapped"
            />
            <StackLayout
                Orientation="Horizontal"
                HorizontalOptions="FillAndExpand"
                BackgroundColor="Blue"
            >
                <Label
                    FontSize="13"
                    Text="Left"
                    TextColor="White"
                    HorizontalOptions="StartAndExpand"
                    VerticalTextAlignment="End"
                />
                <Label
                    FontSize="13"
                    Text="Right"
                    TextColor="White"
                    HorizontalOptions="EndAndExpand"
                    VerticalTextAlignment="End"
                />
            </StackLayout>
        </StackLayout>
    </StackLayout>

结果视图为:

Right-hand label's text wrap breaks the <code>FillAndExpand</code> Short text is ok

所以我可以说出为什么会这样,但当然,我不喜欢它。预期的行为是右侧的stacklayout一直向右扩展。我已经尝试了各种方法来规避这个问题,如果我成功的话就不会在这里。有人有想法吗?

1 个答案:

答案 0 :(得分:1)

不幸的是,它是Xamarin.Forms中的一个错误(可能只支持iOS)。

此案例中的解决方法是使用Grid代替StackLayouthttp://forums.xamarin.com/discussion/comment/152969/#Comment_152969