[英]CarouselView-Xamarin Forms: Data is not getting displayed
I am trying to display data using carousel view in my forms application. 我正在尝试在表单应用程序中使用轮播视图显示数据。 I am not sure what am I missing but data is not getting populated, I have followed almost all available samples but still I have not found any success.
我不确定我缺少什么,但是没有填充数据,我已经追踪了几乎所有可用的样本,但是仍然没有找到任何成功。 Please help me get out of this problem:
请帮助我摆脱这个问题:
I am using the following code in my xaml file: 我在xaml文件中使用以下代码:
<forms:CarouselView x:Name="listview" ItemsSource="postIdList" HeightRequest="200" Margin="5">
<forms:CarouselView.ItemTemplate>
<DataTemplate>
<ContentPage >
<StackLayout >
<Label Text="{Binding .}" FontSize="20" TextColor="Black" HorizontalOptions="Center" />
</StackLayout>
</ContentPage>
</DataTemplate>
</forms:CarouselView.ItemTemplate>
</forms:CarouselView>
And I am trying to populate the data in the following manner in .cs file: 我正在尝试以以下方式在.cs文件中填充数据:
List<string> postIdList = new List<string>
{
"Carousel", "Carousel", "carousel"
};
listview.ItemsSource = postIdList;
If I give a background colour for carousal view I am able to see that colour, but text is not getting displayed. 如果我给背景提供旋转木马视图的颜色,则可以看到该颜色,但不会显示文本。 Please let me know my mistake.
请让我知道我的错误。
In case of a ListView, you need an ObservableCollection instead of a List. 如果是ListView,则需要ObservableCollection而不是List。 Switch it around and see if it works?
切换一下,看看是否可行?
On your XAML you are defining a <ContentPage>
inside the <Datatemplate>
. 在XAML上,您正在
<Datatemplate>
内定义<ContentPage>
<Datatemplate>
。 Replace the <ContentPage>
with a <ViewCell>
or a <Grid>
将
<ContentPage>
替换为<ViewCell>
或<Grid>
Here is a great example on how to use it, you need to keep in mind that CarouselView work like a ListView, it need to have a Datatemplate. 这是一个有关如何使用它的好例子,您需要记住CarouselView就像ListView一样工作,它需要一个Datatemplate。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.