/// <summary> /// Creates this view according to the orientation. /// </summary> /// <param name="newOrientation">The desired orientation.</param> /// <returns>The created view.</returns> private View CreateView(StackOrientation newOrientation) { RelativeLayout layout = new RelativeLayout(); // create the carousel Xamarin.Forms.CarouselView carousel = new Xamarin.Forms.CarouselView(); carousel.SetBinding(Xamarin.Forms.CarouselView.PositionProperty, "SelectedPage"); carousel.SetBinding(ItemsView.ItemsSourceProperty, "Pages"); if (newOrientation == StackOrientation.Vertical) { carousel.ItemTemplate = new DataTemplate(LoadPortraitTemplate); } else { carousel.ItemTemplate = new DataTemplate(LoadLandscapeTemplate); } // bottom buttons var skipLabel = new Label() { Text = Strings.UserOnboarding_Skip, TextColor = Color.White }; skipLabel.SetBinding(IsVisibleProperty, "IsForwardVisible"); var finishTapGestureRecognizer = new TapGestureRecognizer(); finishTapGestureRecognizer.SetBinding(TapGestureRecognizer.CommandProperty, "FinishCommand"); skipLabel.GestureRecognizers.Add(finishTapGestureRecognizer); var forwardLabel = new Label() { Text = Strings.UserOnboarding_Forward, TextColor = Color.White }; forwardLabel.SetBinding(IsVisibleProperty, "IsForwardVisible"); var forwardGestureRecognizer = new TapGestureRecognizer(); forwardGestureRecognizer.SetBinding(TapGestureRecognizer.CommandProperty, "ForwardCommand"); forwardLabel.GestureRecognizers.Add(forwardGestureRecognizer); var okLabel = new Label() { Text = Strings.UserOnboarding_Ok, TextColor = Color.White }; okLabel.SetBinding(IsVisibleProperty, "IsFinishVisible"); okLabel.GestureRecognizers.Add(finishTapGestureRecognizer); var indicators = new CarouselIndicators() { IndicatorWidth = 10, IndicatorHeight = 10, UnselectedIndicator = "unselected_circle.png", SelectedIndicator = "selected_circle.png" }; indicators.SetBinding(CarouselIndicators.PositionProperty, "SelectedPage"); indicators.SetBinding(CarouselIndicators.ItemsSourceProperty, "Pages"); var separator = new BoxView() { Color = Color.White, HeightRequest = 1 }; // add pieces together layout.Children.Add(carousel, widthConstraint: Constraint.RelativeToParent(parent => parent.Width), heightConstraint: Constraint.RelativeToParent(parent => parent.Height)); layout.Children.Add(skipLabel, Constraint.Constant(10), Constraint.RelativeToParent(parent => parent.Height - 30)); layout.Children.Add(forwardLabel, Constraint.RelativeToParent(parent => parent.Width - 50), Constraint.RelativeToParent(parent => parent.Height - 30)); layout.Children.Add(okLabel, Constraint.RelativeToParent(parent => parent.Width - 80), Constraint.RelativeToParent(parent => parent.Height - 30)); layout.Children.Add(indicators, Constraint.RelativeToParent(parent => parent.Width * 0.5 - 15), Constraint.RelativeToParent(parent => parent.Height - 30)); layout.Children.Add(separator, yConstraint: Constraint.RelativeToView(skipLabel, (parent, view) => view.Y - 10), widthConstraint: Constraint.RelativeToParent(parent => parent.Width)); return(layout); }
public CarouselPage() { ObservableCollection <Result> currentRace = new ObservableCollection <Result>(); //var title = new Label { FontSize = 14 }; ObservableCollection <Details> collection = new ObservableCollection <Details> { new Details { obscollection = currentRace }, }; getData(currentUrl); async void getData(string url) { var content = await _client.GetStringAsync(url); var json = JsonConvert.DeserializeObject <RootJSON>(content); ObservableCollection <Result> nextRace = new ObservableCollection <Result>(); Stage stage = json.stage; //Previous previous = json.previous; string previousDate = null; title.Add(stage.name); if (json.previous != null) { previousDate = json.previous.date; } List <Result> results = stage.results; /* * for (int i = 0; i < stage.results.Count; i++) * { * System.Diagnostics.Debug.WriteLine(stage.results[i].category.name + " " + stage.results[i].firstName + " " + stage.results[i].lastName); * }*/ if (url == "https://www.spokesman.online/api/race/current") { for (int i = 0; i < results.Count; i++) { //data.Add(second[i].firstName); //System.Diagnostics.Debug.WriteLine(results[i].firstName); currentRace.Add(results[i]); } } else { for (int i = 0; i < results.Count; i++) { //data.Add(second[i].firstName); nextRace.Add(results[i]); } collection.Add(new Details { obscollection = nextRace, Header = stage.name }); } System.Diagnostics.Debug.WriteLine(stage.name); if (previousDate != null) { getData("https://www.spokesman.online/api/race/Phat%20Wednesday/" + previousDate); } } BackgroundColor = Color.FromHex("#FFFFFF"); StackLayout body = new StackLayout() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; carousel = new Xamarin.Forms.CarouselView() { BackgroundColor = Color.Transparent, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; DataTemplate template = new DataTemplate(() => { var stacksample = new StackLayout() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.Transparent }; Label label = new Label() { //only grabs the first title //Text=title[0] }; ListView lstview = new ListView() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, SeparatorVisibility = SeparatorVisibility.Default, ItemTemplate = new DataTemplate((typeof(cell))), BackgroundColor = Color.Transparent, RowHeight = 35 }; lstview.SetBinding(ListView.ItemsSourceProperty, "obscollection"); lstview.ItemSelected += (object sender, SelectedItemChangedEventArgs e) => { if (e.SelectedItem == null) { return; } var item = e.SelectedItem as Result; //DisplayAlert("Item Selected", item.firstName, "Ok"); detailPage(item); ((ListView)sender).SelectedItem = null; }; stacksample.Children.Add(label); stacksample.Children.Add(lstview); return(stacksample); }); carousel.ItemTemplate = template; carousel.PositionSelected += pageChanged; carousel.ItemsSource = collection; dotLayout = new DotButtonsLayout(collection.Count, Color.FromHex("#311F2D"), 15); foreach (DotButton dot in dotLayout.dots) { dot.Clicked += dotClicked; } //body.Children.Add(title); body.Children.Add(carousel); body.Children.Add(dotLayout); StackLayout stack = new StackLayout() { Children = { body }, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.White }; Padding = new Thickness(0, Device.OnPlatform(5, 0, 0), 0, 0); Content = stack; }
public CarouselPage() { /* * first = new ObservableCollection<Rider> * { * new Rider("00001", "Jamie Carson", "Scotland", "imageurl", 22, "male", "2:52.618", "0", 200), * new Rider("00002", "Stefan Koch", "Germany", "imageurl", 38, "male", "2:54.791", "+2.173", 160), * new Rider("00003", "Matt Falzon", "Australia", "imageurl", 26, "male", "2:57.281", "+4.663", 140), * new Rider("00004", "Cam Barter", "Canada", "imageurl", 22, "male", "2:58.111", "+5.493", 125), * new Rider("00005", "Jack Cropton", "Canada", "imageurl", 18, "male", "2:59.912", "+7.294", 110), * new Rider("00006", "Ed White", "England", "imageurl", 22, "male", "3:00.249", "+7.631", 95) * }; * * second = new ObservableCollection<Rider> * { * new Rider("00001", "Jamie Carson2", "Scotland", "imageurl", 22, "male", "2:52.618", "0", 200), * new Rider("00002", "Stefan Koch2", "Germany", "imageurl", 38, "male", "2:54.791", "+2.173", 160), * new Rider("00003", "Matt Falzon2", "Australia", "imageurl", 26, "male", "2:57.281", "+4.663", 140), * new Rider("00004", "Cam Barter2", "Canada", "imageurl", 22, "male", "2:58.111", "+5.493", 125), * new Rider("00005", "Jack Cropton2", "Canada", "imageurl", 18, "male", "2:59.912", "+7.294", 110), * new Rider("00006", "Ed White2", "England", "imageurl", 22, "male", "3:00.249", "+7.631", 95) * }; * * third = new ObservableCollection<Rider> * { * new Rider("00001", "Jamie Carson3", "Scotland", "imageurl", 22, "male", "2:52.618", "0", 200), * new Rider("00002", "Stefan Koch3", "Germany", "imageurl", 38, "male", "2:54.791", "+2.173", 160), * new Rider("00003", "Matt Falzon3", "Australia", "imageurl", 26, "male", "2:57.281", "+4.663", 140), * new Rider("00004", "Cam Barter3", "Canada", "imageurl", 22, "male", "2:58.111", "+5.493", 125), * new Rider("00005", "Jack Cropton3", "Canada", "imageurl", 18, "male", "2:59.912", "+7.294", 110), * new Rider("00006", "Ed White3", "England", "imageurl", 22, "male", "3:00.249", "+7.631", 95) * };*/ ObservableCollection <String> data = new ObservableCollection <String> { "Test", "test 2" }; List <string> list = new List <string>(); list.Add("asdf"); list.Add("qwerty"); //getData(data); ObservableCollection <Details> collection = new ObservableCollection <Details> { //new Details{obscollection = first}, //new Details{obscollection = second}, //new Details{obscollection = third}, new Details { resultCollection = fourth } }; BackgroundColor = Color.FromHex("#FFFFFF"); StackLayout body = new StackLayout() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; carousel = new Xamarin.Forms.CarouselView() { BackgroundColor = Color.Transparent, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; DataTemplate template = new DataTemplate(() => { var stacksample = new StackLayout() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.Transparent }; ListView lstview = new ListView() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, SeparatorVisibility = SeparatorVisibility.Default, ItemTemplate = new DataTemplate((typeof(cell))), BackgroundColor = Color.Transparent, RowHeight = 35 }; lstview.SetBinding(ListView.ItemsSourceProperty, "list"); lstview.ItemSelected += (object sender, SelectedItemChangedEventArgs e) => { if (e.SelectedItem == null) { return; } //var item = e.SelectedItem as Rider; //DisplayAlert("Item Selected", item.name, "Ok"); //detailPage(item); ((ListView)sender).SelectedItem = null; }; stacksample.Children.Add(lstview); return(stacksample); }); carousel.ItemTemplate = template; carousel.PositionSelected += pageChanged; carousel.ItemsSource = list; dotLayout = new DotButtonsLayout(collection.Count, Color.FromHex("#311F2D"), 15); foreach (DotButton dot in dotLayout.dots) { dot.Clicked += dotClicked; } body.Children.Add(carousel); body.Children.Add(dotLayout); StackLayout stack = new StackLayout() { Children = { body }, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.White }; Padding = new Thickness(0, Device.OnPlatform(5, 0, 0), 0, 0); Content = stack; }