Xamarin.Forms Guides | Samples

Xamarin.Forms.OpenGLView Class

A View that displays OpenGL content.

See Also: OpenGLView


public sealed class OpenGLView : View, IElementConfiguration<OpenGLView>, IOpenGlViewController


OpenGLViews are easiest to program using Shared Projects, in which case the reference to OpenTK is straightforward. The following example shows a simple OpenGL app with a render loop:

C# Example

using Xamarin.Forms;
using OpenTK.Graphics.ES30;

namespace opengl
    public class OpenGLPage : ContentPage
        float red, green, blue;

        public OpenGLPage ()
            Title = "OpenGL";
            var view = new OpenGLView { HasRenderLoop = true };
            var toggle = new Switch { IsToggled = true };
            var button = new Button { Text = "Display" };

            view.HeightRequest = 300;
            view.WidthRequest = 300;

            view.OnDisplay = r => {

                GL.ClearColor (red, green, blue, 1.0f);
                GL.Clear ((ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit));

                red += 0.01f;
                if (red >= 1.0f)
                    red -= 1.0f;
                green += 0.02f;
                if (green >= 1.0f)
                    green -= 1.0f;
                blue += 0.03f;
                if (blue >= 1.0f)
                    blue -= 1.0f;

            toggle.Toggled += (s, a) => {
                view.HasRenderLoop = toggle.IsToggled;
            button.Clicked += (s, a) => view.Display ();

            var stack = new StackLayout { 
                Padding = new Size (20, 20),
                Children = {view, toggle, button}

            Content = stack;


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

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

See Also: View

Public Constructors

Creates a new OpenGLView object with default values.

Public Fields

static readonly
HasRenderLoopPropertyBindableProperty. Identifies the OpenGLView.HasRenderLoop bindable property.

Public Properties

HasRenderLoopBoolean. Whether this OpenGLView has a custom rendering loop.
OnDisplayAction<Rectangle>. Overridden to create a custom rendering loop.

Public Methods

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

Public Events

DisplayRequestedFor internal use by the Xamarin.Forms platform.