Skip to content

Instantly share code, notes, and snippets.

@wbsimms
Created August 15, 2016 21:55
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 wbsimms/778fbbc1ece0ec896f1ab64115818e3f to your computer and use it in GitHub Desktop.
Save wbsimms/778fbbc1ece0ec896f1ab64115818e3f to your computer and use it in GitHub Desktop.
CarouselPage Example
<?xml version="1.0" encoding="utf-8" ?>
<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Carasoul"
xmlns:controls="clr-namespace:Windows.UI.Xaml.Controls;assembly=Windows"
x:Class="Carasoul.MainPage">
<ContentPage x:Name="Page1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Button Grid.Row="1" Clicked="Button_OnClicked" Grid.Column="0" Text="Left 1" TextColor="White">Left 1</Button>
<Button Grid.Row="1" Clicked="Button_OnClicked" Grid.Column="1" Text="Right 1" TextColor="White">Right 1</Button>
</Grid>
</ContentPage>
<ContentPage x:Name="Page2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Button Clicked="Button_OnClicked" Grid.Row="1" Grid.Column="0" Text="Left 2" TextColor="White">Left 2</Button>
<Button Clicked="Button_OnClicked" Grid.Row="1" TextColor="White" Text="Right 2" Grid.Column="1">Right 2</Button>
</Grid>
</ContentPage>
<ContentPage x:Name="Page3">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Button Grid.Row="1" Clicked="Button_OnClicked" Grid.Column="0" Text="Left 3" TextColor="White">Left 3</Button>
<Button Grid.Row="1" Clicked="Button_OnClicked" Grid.Column="1" Text="Right 3" TextColor="White">Right 3</Button>
</Grid>
</ContentPage>
</CarouselPage>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Carasoul
{
public partial class MainPage : CarouselPage
{
public MainPage()
{
InitializeComponent();
}
private void Button_OnClicked(object sender, EventArgs e)
{
var b = (Button) sender;
string[] bits = b.Text.Split(' ');
int pnum = int.Parse(bits[1]);
if (b.Text.Contains("Right"))
{
pnum++;
}
else
{
pnum--;
}
if (pnum < 0)
pnum = 3;
if (pnum > 3)
pnum = 1;
if (pnum == 1)
this.CurrentPage = Page1;
if (pnum == 2)
this.CurrentPage = Page2;
if (pnum == 3)
this.CurrentPage = Page3;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment