Warm tip: This article is reproduced from serverfault.com, please click

How can I use ListView inside a CarouselView?

发布于 2020-11-29 20:24:40

I'm trying to show data from my ObservableCollection named "Stats". It works good when I use this code:

<ListView
    Style="{StaticResource ListViewStyle}"
    ItemsSource="{Binding Stats}"
    HasUnevenRows="true">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

But when I try to place this into the CarouselView like that:

<CarouselView>
     <CarouselView.ItemTemplate >
         <DataTemplate >
             <ListView
                Style="{StaticResource ListViewStyle}"
                ItemsSource="{Binding Stats}"
                HasUnevenRows="true">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
             </ListView>
         </DataTemplate>
    </CarouselView.ItemTemplate>
</CarouselView>

It shows nothing. How can I use ListView inside?

Questioner
Sergey
Viewed
1
Jason 2020-11-30 07:06:41

your Carousel needs an ItemsSource that will be a List<List<T>> (or something like that). Then your ListView's ItemsSource will be the inner List that is the current context of the Carousel. You should be able to bind the ListView's ItemsSource="{Binding .}"