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