Guest User

Untitled

a guest
Jan 24th, 2018
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView"
  2.  
  3. <Grid RowSpacing="0">
  4. <Grid.RowDefinitions>
  5. <RowDefinition Height=".3*"/>
  6. <RowDefinition Height=".7*"/>
  7. </Grid.RowDefinitions>
  8. <cv:CarouselView ItemsSource="{Binding Zoos}" x:Name="CarouselZoos">
  9. <cv:CarouselView.ItemTemplate>
  10. <DataTemplate>
  11. <Grid>
  12. <Grid.RowDefinitions>
  13. <RowDefinition Height="*"/>
  14. <RowDefinition Height="Auto"/>
  15. </Grid.RowDefinitions>
  16. <Image Grid.RowSpan="2" Aspect="AspectFill" Source="{Binding ImageUrl}"/>
  17. <StackLayout Grid.Row="1" BackgroundColor="#80000000" Padding="12">
  18. <Label TextColor="White" Text="{Binding Name}" FontSize="16" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
  19. </StackLayout>
  20. </Grid>
  21. </DataTemplate>
  22. </cv:CarouselView.ItemTemplate>
  23. </cv:CarouselView>
  24. <!--List of Monkeys below-->
  25. </Grid>
  26.  
  27. public class CarouselViewMultiPage : CarouselView
  28. {
  29. List<View> _children = new List<View> { };
  30. public List<View> Children {
  31. get { return _children; }
  32. set {
  33. _children = value;
  34. OnPropertyChanged();
  35. }
  36. }
  37. public CarouselViewMultiPage ()
  38. {
  39. this.ItemTemplate = new CarouselTemplateSelector();
  40. this.ItemsSource = Children;
  41. this.SetBinding(CarouselView.ItemsSourceProperty, "Children");
  42. BindingContext = this;
  43. }
  44. }
  45. public class CarouselTemplateSelector : DataTemplateSelector
  46. {
  47. protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
  48. {
  49. DataTemplate dt = new DataTemplate();
  50. View civ = (View)item;
  51. return new DataTemplate(() =>
  52. {
  53. return civ;
  54. });
  55. }
  56. }
  57.  
  58. public App()
  59. {
  60. // The root page of your application
  61. MainPage = new ContentPage {
  62. Content = new CarouselViewMultiPage
  63. {
  64. HorizontalOptions = LayoutOptions.FillAndExpand,
  65. VerticalOptions = LayoutOptions.FillAndExpand,
  66. Children =
  67. {
  68. new Label() { Text="Page 1"},
  69. new Label() { Text="Page 2"},
  70. new Label() { Text="Page 3"},
  71. }
  72. }
  73. };
  74. }
Add Comment
Please, Sign In to add comment