[英]Going from the carousel page to the carousel view
我在頁面上閱讀了以下消息: https : //docs.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>
我想使用輪播視圖,因為我需要指標。
您的DataTemplate
包含 2 個子元素。 刪除一個,它將起作用。
DataTemplate
只能有 1 個模板內容。
如果你想同時使用這兩個頁面,你可以在任何單個布局中添加兩個頁面,如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>
或者
您可以將兩個頁面代碼合並到一個頁面中
如果您需要不同項目的不同模板,您可以使用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.