Created
March 20, 2016 00:25
-
-
Save davidtavarez/24c951287cdb319c1554 to your computer and use it in GitHub Desktop.
Picture carousel for Android, iOS, WP using Xamarin.Forms. https://cdn.pbrd.co/images/2otpyQam.png
This file contains hidden or 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 Xamarin.Forms; | |
using System.Collections.ObjectModel; | |
namespace NAMESPACE.Controls | |
{ | |
public class PicturesCarousel : ScrollView | |
{ | |
AbsoluteLayout _ElementsStack = new AbsoluteLayout (); | |
public PicturesCarousel (string[] elements, double width, double height, int separator = 1) | |
{ | |
Orientation = ScrollOrientation.Horizontal; | |
Content = this._ElementsStack; | |
if (!Equals (elements, null)) { | |
double x = 0f; | |
foreach (string picture in elements) { | |
var view = new Image () { | |
WidthRequest = width, | |
HeightRequest = height, | |
BackgroundColor = Color.FromRgb (245, 245, 245), | |
Source = picture, | |
Aspect = Aspect.AspectFill | |
}; | |
AbsoluteLayout.SetLayoutFlags (view, AbsoluteLayoutFlags.None); | |
AbsoluteLayout.SetLayoutBounds (view, new Rectangle (x, 0, width, height)); | |
this._ElementsStack.Children.Add (view); | |
x += width + separator; | |
} | |
this._ElementsStack.WidthRequest = x; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment