我在页面上看到了以下消息:https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/carousel-page
CarouselPage已被CarouselView取代,它提供了一个可滚动的布局,用户可以在其中滑动以移动一组项。有关CarouselView的更多信息,请参见Xamarin.Forms CarouselView。
在这方面,我决定开始使用CarouselView。但是,当我试图使用旋转木马来查找页面旋转木马时,得到了一个错误: 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>这是我想得到的结果。
<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>我想使用旋转木马视图,因为我需要指示器。
发布于 2019-11-23 09:24:04
您的DataTemplate包含两个子元素。去掉一个,它就能工作了。
DataTemplate中只能有一个模板内容。
如果您想同时使用这两个页面,您可以在任何一个布局中添加两个页面,如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>
或
您可以将两个页面代码合并到一个页面中。
发布于 2019-11-23 11:05:57
如果对不同项目需要不同的模板,则可以使用DataTemplateSelector:https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/carouselview/populate-data#choose-item-appearance-at-runtime
https://stackoverflow.com/questions/59005796
复制相似问题