Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 哈马林旋转木马_C#_Xamarin_Xamarin.android - Fatal编程技术网

C# 哈马林旋转木马

C# 哈马林旋转木马,c#,xamarin,xamarin.android,C#,Xamarin,Xamarin.android,我不确定我在这里做错了什么 我有一个CarouselPage和一个ContentPage,我想通过编程方式将内容页添加到CarouselPage中,但是当我这样做时,应用程序中什么也没有发生 我可以看到添加到列表中的项目,但当我运行下面的代码时,页面不会显示 非常感谢您对我所做错事的任何帮助:) MainPage.xaml <?xml version="1.0" encoding="utf-8" ?> <CarouselPage

我不确定我在这里做错了什么

我有一个CarouselPage和一个ContentPage,我想通过编程方式将内容页添加到CarouselPage中,但是当我这样做时,应用程序中什么也没有发生

我可以看到添加到列表中的项目,但当我运行下面的代码时,页面不会显示

非常感谢您对我所做错事的任何帮助:)

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="DemoApp2.MainPage"
/>
他们有一个这样做的明确例子。如果要使用
项目资源
,必须提供
数据模板
。否则,您将修改页面的
子项

Children.Add(new StoryPage("This is page 1"));
Children.Add(new StoryPage("This is page 2"));
Children.Add(new StoryPage("This is page 3"));
Children.Add(new StoryPage("This is page 4"));
Children.Add(new StoryPage("This is page 5"));

多谢各位much@fox909a嗨,如果答案有帮助并且解决了这个问题,记得标记那个。然后其他遇到同样问题的人就会知道答案。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="DemoApp2.StoryPage">
    <ContentPage.Content>
        <StackLayout>
            <Label x:Name="YourLableName"
                   Text="Not Set"
                   TextColor="Black"
                VerticalOptions="CenterAndExpand" 
                HorizontalOptions="CenterAndExpand" />
        </StackLayout>
    </ContentPage.Content>
</ContentPage>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace DemoApp2
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class StoryPage : ContentPage
    {


        public string PageText = "";

        public StoryPage()
        {
            InitializeComponent();

            PageText = "";

        }


        public StoryPage(string pageTextIn)
        {
            InitializeComponent();

            YourLableName.TextColor = Color.Black;
            YourLableName.Text = pageTextIn;

        }

        protected override void OnAppearing()
        {
            Debug.WriteLine("OnAppearing");
        }

        protected override void OnDisappearing()
        {
            Debug.WriteLine("OnDisappearing");
        }

    }
}
Children.Add(new StoryPage("This is page 1"));
Children.Add(new StoryPage("This is page 2"));
Children.Add(new StoryPage("This is page 3"));
Children.Add(new StoryPage("This is page 4"));
Children.Add(new StoryPage("This is page 5"));