I'm not sure but i spent already 1 day with this problem.
I try to bind a Collection to the Xamarin Forms Carousel.
XAML Code:
<cv:CarouselView ItemsSource="{Binding MainSlider}" x:Name="carousel" >
<cv:CarouselView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Name}" />
</DataTemplate>
</cv:CarouselView.ItemTemplate>
</cv:CarouselView>
Xamarin Forms
public class SliderItem
{
public string ImageUrl { get; set; }
public string Name { get; set; }
}
...
public ObservableCollection<SliderItem> MainSlider { get; set; }
...
InitializeComponent();
MainSlider = new ObservableCollection<SliderItem> {
new SliderItem
{
ImageUrl = "1.jpg",
Name = "Test 1"
},
new SliderItem
{
ImageUrl = "2.jpg",
Name="Test 2"
}
};
this.BindingContext = this;
The Label will keep empty and i cannot find the problem.
Anyone an idea?
尝试在InitializeComponent()之前填充列表
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.