2016-03-01 150 views
1

我收到一個錯誤 - 「旋轉木馬沒有孩子」。旋轉木馬 - 將不同頁面添加到旋轉木馬

我使用了Xamarin的旋轉木馬樣本。如果頁面相同,則傳送帶工作。我的要求是,我的網頁是不同的,但我希望它在旋轉木馬上工作。

  1. 第1頁 - 圖片
  2. 頁2 - 按鈕
  3. 頁3 - 檢查框

MainPage.xaml中

<?xml version="1.0" encoding="utf-8" ?> 
    <CarouselPage xmlns="http://xamarin.com/schemas/2014/forms" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
        x:Class="CarouselApp.MainPage"> 
     <CarouselPage.ItemTemplate> 
      <DataTemplate> 
       <ContentPage> 
        <ContentPage.Padding> 
         <OnPlatform x:TypeArguments="Thickness" iOS="0,40,0,0" Android="0,40,0,0"> 
        </ContentPage.Padding> 
        <StackLayout> 
          <ContentView BindingContext="PageName"></ContentView> 
        </StackLayout> 
       </ContentPage> 
      </DataTemplate> 
     </CarouselPage.ItemTemplate> 
    </CarouselPage> 

MainPage.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

using Xamarin.Forms; 

namespace CarouselApp 
{ 
    public partial class MainPage : CarouselPage 
    { 
     public MainPage() 
     { 
      InitializeComponent(); 
      ItemsSource = CarouselAppDataModel.All; 
     } 
    } 
} 

的DataModel

using System; 
using System.Collections.Generic; 
using System.Collections.ObjectModel; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using Xamarin.Forms; 

namespace CarouselApp 
{ 
    public class CarouselDataModel : ContentView 
    { 
     public ContentView PageName { get; set; } 
     public static IList<CarouselDatModel> All { get; set; } 

     private Carousel03 fl3 as new Carousel03; 
     private Carousel04 fl4 as new Carousel04; 

     public CarouselDataDataModel() 
     { 
      All = new ObservableCollection<CarouselDataModel> 
      { 
       new CarouselDataModel 
       { 
        PageName = fl3 
       }, 
       new CarouselDataModel 
       { 
        PageName = fl4 
       } 
      }; 
     } 
    } 
} 
+0

XAML頁
<內容查看的BindingContext = 「頁面名稱」> CipherIS

+0

真的不清楚你想要解決什麼問題。 CarouselPage可以包含ContentPage實例。它們不一定是相同的 - 它們可以包含任何你想要的內容。 – Jason

回答

0

因爲你的頁面都不同,並且您使用XAML ...而不是使用數據模板,只需創建您的XAML連續三個內容頁面,如下

<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms" 
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
       x:Class="CarouselPageNavigation.MainPage"> 
    <ContentPage> 
     <ContentPage.Padding> 
      <OnPlatform x:TypeArguments="Thickness" iOS="0,40,0,0" Android="0,40,0,0" /> 
     </ContentPage.Padding> 
     <StackLayout> 
      <Label Text="Red" FontSize="Medium" HorizontalOptions="Center" /> 
      <BoxView Color="Red" WidthRequest="200" HeightRequest="200" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" /> 
     </StackLayout> 
    </ContentPage> 
    <ContentPage> 
     ... 
    </ContentPage> 
    <ContentPage> 
     ... 
    </ContentPage> 
</CarouselPage>