Skip to content

Instantly share code, notes, and snippets.

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
LoadApplication(new App());
}
@chrisriesgo
chrisriesgo / CarouselLayout.cs
Created June 19, 2016 13:12
Remove all System.Timer references
// ...
async Task UpdateSelectedItem ()
{
await Task.Delay(300);
SelectedItem = SelectedIndex > -1 ? Children[SelectedIndex].BindingContext : null;
}
// ...
@chrisriesgo
chrisriesgo / CarouselViewWithVMViews.cs
Created July 12, 2015 15:37
An example showing how to have dynamic item templates driven off of the bound viewmodels.
public class App : Application
{
public IEnumerable<ICarouselViewModel> _pages;
public App()
{
_pages = new List<ICarouselViewModel>()
{
new PageOneViewModel(),
new PageTwoViewModel()
public HomePage(CarouselLayout.IndicatorStyleEnum indicatorStyle)
{
_indicatorStyle = indicatorStyle;
viewModel = new SwitcherPageViewModel();
BindingContext = viewModel;
Title = _indicatorStyle.ToString();
relativeLayout = new RelativeLayout
void ItemsSourceChanged ()
{
if (ItemsSource == null) return;
CreateTabs();
}
void CreateTabs()
{
if(Children != null && Children.Count > 0) Children.Clear();
void ItemsSourceChanged ()
{
if (ItemsSource == null) return;
var countDelta = ItemsSource.Count - Children.Count;
if (countDelta > 0) {
for (var i = 0; i < countDelta; i++)
{
CreateDot();
public enum IndicatorStyleEnum
{
None,
Dots,
Tabs
}
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 SnapScroll ()
{
var roughIndex = (float)_scrollView.ScrollX / _scrollView.Width;
var targetIndex =
_deltaX < 0 ? Math.Floor (roughIndex)
: _deltaX > 0 ? Math.Ceil (roughIndex)
: Math.Round (roughIndex);
ScrollToIndex ((int)targetIndex);
public static readonly BindableProperty ItemsSourceProperty =
BindableProperty.Create<CarouselLayout, IList> (
view => view.ItemsSource,
null,
propertyChanging: (bindableObject, oldValue, newValue) => {
((CarouselLayout)bindableObject).ItemsSourceChanging ();
},
propertyChanged: (bindableObject, oldValue, newValue) => {
((CarouselLayout)bindableObject).ItemsSourceChanged ();
}