Hello guys,
I'm trying to bind a CarouselPage.ItemsSource but i only got a result when the list is populate on the constructor.
I read this in Xamarin Documentation:
"The CarouselPage is populated with data by setting the ItemsSource property in the constructor for the code-behind file"
We can only bind itemsSource on the constructor?
I need to bind items in the OnNavigatedTo methods (PRISM MVVM)
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"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="APP.Views.Manager.Needs"
ItemsSource="{Binding Pages}">
<CarouselPage.ItemTemplate>
<DataTemplate>
<ContentPage BackgroundColor="Red">
<Label Text="Hello world!"/>
</ContentPage>
</DataTemplate>
</CarouselPage.ItemTemplate>
</CarouselPage>
ViewModel:
public ObservableCollection<ContentPage> Pages { get; private set; }
public async void OnNavigatedTo(NavigationParameters parameters)
{
List<ContentPage> ContentPages = new List<ContentPage>();
ContentPages.Add(new ContentPage());
Pages = new ObservableCollection<ContentPage>(ContentPages);
}
Best regards