shuhelohelo’s blog

Xamarin.Forms多めです.

CollectionViewのネスト

CollectionViewをネストすると,以下のような表示になる.

f:id:shuhelohelo:20200630005844p:plain

        <CollectionView ItemsSource="{Binding AnimeInfos}">
            <CollectionView.ItemsLayout>
                <LinearItemsLayout ItemSpacing="10" Orientation="Vertical" />
            </CollectionView.ItemsLayout>
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Frame BackgroundColor="LightPink">
                            <StackLayout>
                                <Label Text="{Binding Title}" />
                                <Label Text="{Binding OfficialUrl}" />
                                <CollectionView
                                    BackgroundColor="LightBlue"
                                    ItemsSource="{Binding Schedules}"
                                    VerticalOptions="Center">
                                    <CollectionView.ItemsLayout>
                                        <LinearItemsLayout Orientation="Vertical" />
                                    </CollectionView.ItemsLayout>
                                    <CollectionView.ItemTemplate>
                                        <DataTemplate>
                                            <StackLayout VerticalOptions="Center">
                                                <Label Text="{Binding Station}" />
                                                <Label Text="{Binding DateTimeFrom}" />
                                            </StackLayout>
                                        </DataTemplate>
                                    </CollectionView.ItemTemplate>
                                </CollectionView>
                            </StackLayout>
                        </Frame>
                    </Grid>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>

stackoverflow.com

CollectionView使わないで,StackLayoutでBindableLayout使えばよかった.

shuhelohelo.hatenablog.com

                            <StackLayout>
                                <Label FontSize="Large" Text="{Binding Title}" />
                                <Label HorizontalOptions="End" Text="{Binding Schedules[0].DateTimeFrom}" />
                                <StackLayout BindableLayout.ItemsSource="{Binding Schedules}">
                                <BindableLayout.ItemTemplate>
                                    <DataTemplate>
                                        <StackLayout>
                                            <Label Text="{Binding Station}" />
                                            <Label Text="{Binding DateTimeFrom}" />
                                        </StackLayout>
                                    </DataTemplate>
                                </BindableLayout.ItemTemplate>
                            </StackLayout>