Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

[PRISM] Carousel Page Binding ItemsSource

$
0
0

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) :neutral:

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


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>