Xamarin.Forms Guides | Samples

Xamarin.Forms.CarouselPage Class

A Page that users can swipe from side to side to display pages of content, like a gallery.

See Also: CarouselPage

Syntax

[Xamarin.Forms.RenderWith(typeof(Xamarin.Forms.Platform._CarouselPageRenderer))]
public class CarouselPage : MultiPage<ContentPage>, IElementConfiguration<CarouselPage>

Remarks

The CarouselPage provides a navigation experience that will feel natural and familiar to Windows Phone users. By using Device.OnPlatform, application developers can provide customized navigation on a per-platform basis. For example, an application developer could use a NavigationPage for Android and iOS, and use a CarouselPage on Windows Phone.

The following XAML example, when properly included and referenced in a Xamarin.Forms project, creates a CarouselPage that displays three simple ContentPage elements:

XAML 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" x:Class="XamlExample1.MyPage">
    <ContentPage>
        <StackLayout>
            <Label Text="Red" />
            <BoxView Color="Red" VerticalOptions="FillAndExpand" />
        </StackLayout>
    </ContentPage>
    <ContentPage>
        <StackLayout>
            <Label Text="Green" />
            <BoxView Color="Green" VerticalOptions="FillAndExpand" />
        </StackLayout>
    </ContentPage>
    <ContentPage>
        <StackLayout>
            <Label Text="Blue" />
            <BoxView Color="Blue" VerticalOptions="FillAndExpand" />
        </StackLayout>
    </ContentPage>
</CarouselPage>

The following C# example creates a CarouselPage that displays three simple ContentPage elements:

C# Example

List<ContentPage> pages = new List<ContentPage> (0);
Color[] colors = { Color.Red, Color.Green, Color.Blue };
foreach (Color c in colors) {
    pages.Add (new ContentPage { Content = new StackLayout {
            Children = {
                new Label { Text = c.ToString () },
                new BoxView {
                    Color = c,
                    VerticalOptions = LayoutOptions.FillAndExpand
                }
            }
        }
    });
}

MainPage = new CarouselPage {
    Children = { pages [0],
                 pages [1],
                 pages [2] }
};
Note: When embedding a CarouselPage into a MasterDetailPage.Detail, application developers should set MasterDetailPage.IsGestureEnabled to false to prevent gesture conflicts between the CarouselPage and MasterDetailPage.

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0, 1.4.0.0, 1.5.0.0, 2.0.0.0

The members of Xamarin.Forms.CarouselPage are listed below.

See Also: Inherited members from Xamarin.Forms.MultiPage<Xamarin.Forms.ContentPage>

Public Constructors

Initializes a new instance of the CarouselPage class.

Public Methods

Protected Methods

override
CreateDefault(Object) : ContentPage
Creates a default page, suitable for display in thisCarouselPage, for an object.