Xamarin.Forms Guides | Samples

Xamarin.Forms.BoxView Class

A View used to draw a solid colored rectangle.

See Also: BoxView

Syntax

[Xamarin.Forms.RenderWith(typeof(Xamarin.Forms.Platform._BoxViewRenderer))]
public class BoxView : View, IElementConfiguration<BoxView>

Remarks

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 = 
                {
                    header,
                    boxView
                }
            };
        }
    }
}

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.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

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