Xamarin.Forms Guides | Samples

Xamarin.Forms.BoxView Class

A View used to draw a solid colored rectangle.

See Also: BoxView


public class BoxView : View, IElementConfiguration<BoxView>


BoxView is a useful stand-in for images or custom elements when doing initial prototyping. BoxView has a default size request of 40x40. If you need a different size, assign the VisualElement.WidthRequest and VisualElement.HeightRequest properties.

XAML for Xamarin.Forms supports the following properties for the BoxView class:

The example below creates a red Boxview with the default width and height.

XAML Example

<BoxView Color="Red" />

The following example shows a basic use:

C# Example

using System;
using Xamarin.Forms;

namespace FormsGallery
    class BoxViewDemoPage : ContentPage
        public BoxViewDemoPage()
            Label header = new Label
                Text = "BoxView",
                Font = Font.BoldSystemFontOfSize(50),
                HorizontalOptions = LayoutOptions.Center

            BoxView boxView = new BoxView
                Color = Color.Accent,
                WidthRequest = 150,
                HeightRequest = 150,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.CenterAndExpand

            // Accomodate iPhone status bar.
            this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);

            // Build the page.
            this.Content = new StackLayout
                Children = 


Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions:,,,,,,

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

See Also: View

Public Constructors

Initializes a new instance of the BoxView class.

Public Fields

static readonly
ColorPropertyBindableProperty. Identifies the Color bindable property.

Public Properties

ColorColor. Gets or sets the color which will fill the rectangle. This is a bindable property.

Public Methods

On<T>() : IPlatformElementConfiguration<T, BoxView>
Returns the platform-specific instance of this BoxView, on which a platform-specific method may be called.

Protected Methods

OnSizeRequest(Double, Double) : SizeRequest
Method that is called when a size request is made to the box view.