首页 > 解决方案 > Xamarin 中的 Flex 布局

问题描述

我在每个关于 html 和 css 的项目中都使用 flex。我在 XAML <flexlayout 中发现工作方式相同,所以我尝试

<ContentPage.Content>
        <StackLayout>
            <FlexLayout>
                <FlexLayout>
                    <Label Text="It don't work"></Label>
                </FlexLayout>
                <Label Text="Is it work"></Label>
               
            </FlexLayout>
        </StackLayout>
    </ContentPage.Content>

它在 flex 内部没有显示任何 flex,所以里面什么都没有,但我可以看到它工作的东西。我在这里做错了什么在 xarmarin/xaml 中还是新的

Microsoft doc 也是一种基本的https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/flex-layout

标签: c#xamlxamarin

解决方案


我在 github 上找到一个线程来讨论嵌套 FlexLayout 不可见:

https://github.com/xamarin/Xamarin.Forms/issues/9537

我还找到了一种解决方法,您可以将您的子 flex 布局放入其中:

<StackLayout>
        <FlexLayout>
            <StackLayout WidthRequest="100">
                <FlexLayout>
                    <Label Text="It don't work" />
                </FlexLayout>
            </StackLayout>
            <Label FlexLayout.AlignSelf="Center" Text="Is it work" />
        </FlexLayout>
    </StackLayout>

在此处输入图像描述


推荐阅读