2016-03-01 175 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>