Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView"
- <Grid RowSpacing="0">
- <Grid.RowDefinitions>
- <RowDefinition Height=".3*"/>
- <RowDefinition Height=".7*"/>
- </Grid.RowDefinitions>
- <cv:CarouselView ItemsSource="{Binding Zoos}" x:Name="CarouselZoos">
- <cv:CarouselView.ItemTemplate>
- <DataTemplate>
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="*"/>
- <RowDefinition Height="Auto"/>
- </Grid.RowDefinitions>
- <Image Grid.RowSpan="2" Aspect="AspectFill" Source="{Binding ImageUrl}"/>
- <StackLayout Grid.Row="1" BackgroundColor="#80000000" Padding="12">
- <Label TextColor="White" Text="{Binding Name}" FontSize="16" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
- </StackLayout>
- </Grid>
- </DataTemplate>
- </cv:CarouselView.ItemTemplate>
- </cv:CarouselView>
- <!--List of Monkeys below-->
- </Grid>
- public class CarouselViewMultiPage : CarouselView
- {
- List<View> _children = new List<View> { };
- public List<View> Children {
- get { return _children; }
- set {
- _children = value;
- OnPropertyChanged();
- }
- }
- public CarouselViewMultiPage ()
- {
- this.ItemTemplate = new CarouselTemplateSelector();
- this.ItemsSource = Children;
- this.SetBinding(CarouselView.ItemsSourceProperty, "Children");
- BindingContext = this;
- }
- }
- public class CarouselTemplateSelector : DataTemplateSelector
- {
- protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
- {
- DataTemplate dt = new DataTemplate();
- View civ = (View)item;
- return new DataTemplate(() =>
- {
- return civ;
- });
- }
- }
- public App()
- {
- // The root page of your application
- MainPage = new ContentPage {
- Content = new CarouselViewMultiPage
- {
- HorizontalOptions = LayoutOptions.FillAndExpand,
- VerticalOptions = LayoutOptions.FillAndExpand,
- Children =
- {
- new Label() { Text="Page 1"},
- new Label() { Text="Page 2"},
- new Label() { Text="Page 3"},
- }
- }
- };
- }
Add Comment
Please, Sign In to add comment