首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >旋转木马--向旋转木马添加不同的页面

旋转木马--向旋转木马添加不同的页面
EN

Stack Overflow用户
提问于 2016-03-01 16:41:51
回答 1查看 1.7K关注 0票数 1

我收到了一个错误--“旋转木马没有孩子”。

我用了Xamarin的旋转木马样本。如果页面相同,旋转木马就能工作。我的要求是,我的网页是不同的,但我希望它工作在一个旋转木马。

  1. 第1页-图像
  2. 第2页-按钮
  3. 第3页-复选框

MainPage.xaml

代码语言:javascript
复制
    <?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

代码语言:javascript
复制
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

代码语言:javascript
复制
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
                }
            };
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2016-11-17 01:57:33

因为你的页面都不一样,你用的是XAML.与其使用数据模板,不如在XAML中创建三个连续的内容页,如下所示

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35728491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档