首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >元素自动Grid.Row和Grid.Column

元素自动Grid.Row和Grid.Column
EN

Stack Overflow用户
提问于 2020-09-11 14:28:03
回答 1查看 175关注 0票数 0

我有一个MainPage.xaml代码:

代码语言:javascript
复制
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="GridTest.MainPage">
    <ScrollView>
            <Grid x:Name="test" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="100" />
                    <RowDefinition Height="100" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0.5*" />
                    <ColumnDefinition Width="0.5*" />
                </Grid.ColumnDefinitions>
                <Button Text="Hello, world" Grid.Column="0" Grid.Row="0"></Button>
                <Button Text="Hello, world" Grid.Column="1" Grid.Row="0"></Button>
            </Grid>
        </ScrollView>
        
</ContentPage>

是否可以自动设置按钮参数Grid.Row和Grid.Column?不是手动的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-14 01:42:57

是否可以自动设置按钮参数Grid.Row和Grid.Column?不是手动的

作为Jason,Grid不会自动安排子视图。默认情况下,Grid.RowGrid.Column的值将为。

对于这个特性,尝试设置使用CollectionView代替。将GridItemsLayout设置为ItemsLayout以在垂直网格中显示项目。

检查代码:

代码语言:javascript
复制
<CollectionView>
    <CollectionView.ItemsLayout>
        <GridItemsLayout Orientation="Vertical" Span="2"/>
    </CollectionView.ItemsLayout>
    <CollectionView.ItemsSource>
        <x:Array Type="{x:Type x:String}">
            <x:String>Hello, world</x:String>
            <x:String>Hello, world</x:String>
            <x:String>Hello, world</x:String>
            <x:String>Hello, world</x:String>
        </x:Array>
    </CollectionView.ItemsSource>
    <CollectionView.ItemTemplate>
        <DataTemplate>
            <StackLayout>
                <Button Text="{Binding }"/>
            </StackLayout>
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63849033

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档