【发布时间】:2019-10-25 04:04:43
【问题描述】:
我创建了包含幻灯片集合的轮播视图。每张幻灯片都包含图像、消息和颜色。它存储在 ObservableCollection 中。我的系列有三种颜色。第一张幻灯片/页面应该是黄色的,第二张应该是红色的,第三张应该是蓝色的。我遇到的问题是,当应用程序启动时,轮播中的所有幻灯片都是蓝色的。我需要每张幻灯片/页面有不同的颜色。
Carousel.ItemsSource = slides = new ObservableCollection<Slides>(new[]
{
new Slides("money", "Some Description", BackgroundColor = Color.Yellow),
new Slides("money", "Some Description2", BackgroundColor = Color.Red),
new Slides("money", "Some Description3",BackgroundColor = Color.Blue)});
<Control:CarouselViewControl x:Name="Carousel"
ShowIndicators="True"
BackgroundColor="{Binding Color}"
CurrentPageIndicatorTintColor="Black">
<Control:CarouselViewControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ContentView Grid.Row="0" Padding="60,30,60,0">
<Image Source="{Binding Image}" Aspect="AspectFit"/>
</ContentView>
<ContentView Grid.Row="1" Padding="20,50,20,0">
<Label Text="{Binding Message}" TextColor="black"
HorizontalOptions="CenterAndExpand"
FontSize="Large"/>
</ContentView>
</Grid>
</DataTemplate>
</Control:CarouselViewControl.ItemTemplate>
</Control:CarouselViewControl>
我希望每个页面都有不同的颜色。
【问题讨论】:
-
您使用的是哪个轮播视图?但一般情况下,您需要在 ItemTemplate 级别绑定颜色。
-
能不能显示你的
Slides,数据绑定正确吗? -
我正在使用一个名为 CarouselView.FormsPlugin 的轮播插件。幻灯片添加到 xaml 代码顶部的 ObservableCollection 中。