[英]Going from the carousel page to the carousel view
I read the following message on the page: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/carousel-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.
CarouselPage 已被 CarouselView 取代,它提供了一个可滚动的布局,用户可以在其中滑动以在项目集合中移动。 For more information about the CarouselView, see Xamarin.Forms CarouselView.
有关 CarouselView 的详细信息,请参阅 Xamarin.Forms CarouselView。
In this regard, I decided to start using the CarouselView.对此,我决定开始使用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.
但是,当我尝试使用轮播查看页面轮播时出现错误:多次设置 ElementTemplateContent 属性。
<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.您的
DataTemplate
包含 2 个子元素。 Remove one and it will work.删除一个,它将起作用。
There can be only be 1 template content inside DataTemplate
. DataTemplate
只能有 1 个模板内容。
If you want to use both,you can add both pages in any single layout like StackLayout
, ContentView
, ContentPage
etc:如果你想同时使用这两个页面,你可以在任何单个布局中添加两个页面,如
StackLayout
、 ContentView
、 ContentPage
等:
<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 -运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.