Created
December 14, 2019 19:44
-
-
Save Pujolsluis/ee42cf5e604a2f8824beae047fa3f560 to your computer and use it in GitHub Desktop.
Update ItemSelected Event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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