繁体   English   中英

Xamarin动态网格布局

[英]Xamarin dynamic grid layout

我有一个具有“ ValueType”之类的属性的对象的集合,基于此属性,我调用一个DataTemplateSelector类,该类将返回要为该对象显示的控件的类型。

<control:ControlDataTemplateSelector x:Key="personDataTemplateSelector"
                RangeTemplate="{StaticResource rangeControl}"
                EnumTemplate="{StaticResource pickControl}"
                DateTemplate="{StaticResource dateControl}"/>

<DataTemplate x:Key="rangeControl">
                <ViewCell>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <control:ScreenLabel   Grid.Row="0" Grid.Column="{Binding Path=SortOrder, Converter={StaticResource sortOrderToColIndexConverter}}"  Text="{Binding Path=TraitDescription}" />
                        <Entry Grid.Row="1" Grid.Column="{Binding Path=SortOrder, Converter={StaticResource sortOrderToColIndexConverter}}"   />
                    </Grid>
                </ViewCell>
            </DataTemplate>
            <DataTemplate x:Key="dateControl">
                <ViewCell>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <control:ScreenLabel   Grid.Row="0" Grid.Column="{Binding Path=SortOrder, Converter={StaticResource sortOrderToColIndexConverter}}" Text="{Binding Path=TraitDescription}" />
                        <DatePicker Grid.Row="1" Grid.Column="{Binding Path=SortOrder, Converter={StaticResource sortOrderToColIndexConverter}}"></DatePicker>
                    </Grid>
                </ViewCell>
            </DataTemplate>
            <DataTemplate x:Key="pickControl">
                <ViewCell>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <control:ScreenLabel   Grid.Row="0" Grid.Column="{Binding Path=SortOrder, Converter={StaticResource sortOrderToColIndexConverter}}"  Text="{Binding Path=TraitDescription}" />
                        <Picker Grid.Row="1" Grid.Column="{Binding Path=SortOrder, Converter={StaticResource sortOrderToColIndexConverter}}"  />
                    </Grid>
                </ViewCell>
            </DataTemplate>

我在以两列格式在网格中显示这些对象时遇到问题,例如,如果集合中有9个对象,则需要显示一个表格视图,该表格视图具有4行(每行2列)和第5行(具有一列)。

用我当前的代码,我得到一种之字形的布局。 但我需要这样需要一些建议

我正在寻找需要在iOS和Droid中工作的解决方案

我会在您的ViewCells内部使用StackLayouts而不是Grids。 你可以做:

        <StackLayout VerticalOptions="FillAndExpand" >
            <control:ScreenLabel Text="{Binding Path=TraitDescription}" />
            <Entry />
        </StackLayout>

您确定绑定正确返回吗? 我尚未在属性上看到逗号分隔的标记扩展设置。

任何寻求答案的人都可以使用FLowlist视图控件来解决它。 它提供了并排查看的选项

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM