JasonC
JasonC

Reputation: 338

How to use a CarouselView in .NET MAUI C#?

I am new to .NET MAUI and found the CarouselView control and am having a hard time using it. I created a simple app that displays names of recipes. In the MainPage.xaml I have a CarouselView as follows:

            <CarouselView ItemsSource="{Binding Recipes}">
                <CarouselView.ItemTemplate>
                    <DataTemplate x:DataType="models:Recipe">
                        <Label Text="{Binding Name}"/>
                    </DataTemplate>
                </CarouselView.ItemTemplate>
            </CarouselView>

When I try to run the code above using Visual Studio running for a "Windows Machine" a white window pops up but never fills, the loading wheel just keeps spinning as the page is unresponsive.

If I switch the code to use a collection view as shown below the app launches just fine and displays all the recipe names.

            <CollectionView ItemsSource="{Binding Recipes}">
                <CollectionView.ItemTemplate>
                    <DataTemplate x:DataType="models:Recipe">
                        <Label Text="{Binding Name}"/>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>

I tried to follow this sample code in the Microsoft's documents but haven't made any progress yet: https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/carouselview/?view=net-maui-7.0

If someone could point out the problem in my implementation using a CarouselView and/or point me to another example on how to use a CarouselView I would be greatly appreciative.

Upvotes: 1

Views: 4587

Answers (1)

Guangyu Bai - MSFT
Guangyu Bai - MSFT

Reputation: 4576

This is an issue on the windows platform. I tested on the Android platform and it works well. You can report it as an issue about the CarouselView on the windows platform.

In addition, you can use the Collectionview by setting the ItemsLayout="HorizontalList" to achieve the CarouselView format.

Upvotes: 2

Related Questions