Skip to content

Instantly share code, notes, and snippets.

@chrisriesgo
Last active August 29, 2015 14:23
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 chrisriesgo/5cd9db5301916a62cea7 to your computer and use it in GitHub Desktop.
Save chrisriesgo/5cd9db5301916a62cea7 to your computer and use it in GitHub Desktop.
void NativeScrolled (object sender, EventArgs e)
{
var center = _native.ContentOffset.X + (_native.Bounds.Width / 2);
((CarouselLayout)Element).SelectedIndex = ((int)center) / ((int)_native.Bounds.Width);
}
void ElementPropertyChanged(object sender, PropertyChangedEventArgs e) {
if (e.PropertyName == CarouselLayout.SelectedIndexProperty.PropertyName && !Dragging) {
ScrollToSelection (false);
}
}
void ScrollToSelection (bool animate)
{
if (Element == null) return;
_native.SetContentOffset (new CoreGraphics.CGPoint
(_native.Bounds.Width * Math.Max(0, ((CarouselLayout)Element).SelectedIndex),
_native.ContentOffset.Y), animate);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment