Skip to content

Instantly share code, notes, and snippets.

@Pujolsluis
Created December 14, 2019 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pujolsluis/ee42cf5e604a2f8824beae047fa3f560 to your computer and use it in GitHub Desktop.
Save Pujolsluis/ee42cf5e604a2f8824beae047fa3f560 to your computer and use it in GitHub Desktop.
Update ItemSelected Event
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SliderViewSample.Models;
using SliderViewSample.ViewModels;
using Xamarin.Forms;
namespace SliderViewSample
{
public partial class MainPage : ContentPage
{
MainPageViewModel Context;
public MainPage()
{
InitializeComponent();
this.BindingContext = new MainPageViewModel();
MainCarousel.CurrentItemChanged += (sender, args) =>
{
if (!(args.CurrentItem is SliderViewItem item))
return;
if (CarouselStepBar.Steps > 0)
CarouselStepBar.StepSelected = (int)item.Step;
};
CarouselStepBar.OnStepSelected += (sender, args) =>
{
if (!(args is int step))
return;
var value = step;
MainCarousel.Position = --value;
};
}
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
Context = this.BindingContext as MainPageViewModel;
if(Context.Data.Count > 0)
{
CarouselStepBar.StepSelected = 1;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment