I read the following message on the page: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/carousel-page
The CarouselPage has been superseded by the CarouselView, which provides a scrollable layout where users can swipe to move through a collection of items. For more information about the CarouselView, see Xamarin.Forms CarouselView.
In this regard, I decided to start using the CarouselView. But when I tried to use the carousel to look out for the page carousel and got an error: the ElementTemplateContent property was set more than once.
<CarouselView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:test.Views"
x:Class="test.Corusel">
<CarouselView.ItemTemplate>
<DataTemplate>
<local:Page1></local:Page1>
<local:Page2></local:Page2>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
Here is the result I want to get.
<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:test.Views"
x:Class="test.Corusel">
<CarouselPage.Children>
<local:Page1></local:Page1>
<local:Page2></local:Page2>
</CarouselPage.Children>
I wanted to use the carousel view because I need indicators.
Your DataTemplate
contains 2 child elements. Remove one and it will work.
There can be only be 1 template content inside DataTemplate
.
If you want to use both,you can add both pages in any single layout like StackLayout
, ContentView
, ContentPage
etc:
<CarouselView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:test.Views"
x:Class="test.Corusel">
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
<local:Page1></local:Page1>
<local:Page2></local:Page2>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
Or
you can merge both pages code into a single page
如果您需要不同项目的不同模板,您可以使用DataTemplateSelector
: https : //docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/carouselview/populate-data#choose-item-appearance-at -运行
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.