Xuni User Guide > Xuni Controls > Gauge > Quick Start: Add and Configure > LinearGauge Quick Start |
This section describes how to add a LinearGauge control to your portable or shared app and set its value. For information on how to add Xuni components in C# or XAML, see Adding Xuni Components using C# or Adding Xuni Components using XAML.
This topic comprises of two steps:
The following image shows how the LinearGauge appears after completing the steps above:
The Value
property denotes the value of the gauge. Multiple ranges can be added to a single Gauge and the position of the range is defined by the Min
and Max
properties of the range. If you set the Gauge's IsReadOnly
property to false, then the user is able to edit the value by tapping on the gauge.
Note: XuniLinearGauge.Origin property can be used to change the origin of the LinearGauge pointer. By default, the Origin is set to 0. |
Complete the following steps to initialize a LinearGauge control in C# or XAML.
QuickStart.cs
) to your Portable or Shared project and include Xuni Gauge and Xamarin references as shown below.
C# |
Copy Code |
---|---|
using Xuni.Xamarin.Gauge; using Xamarin.Forms; |
GetLinearGauge()
.
C# |
Copy Code |
---|---|
public static XuniLinearGauge GetLinearGauge() { // Instantiate LinearGauge and set its properties XuniLinearGauge gauge = new XuniLinearGauge(); gauge.HeightRequest = 50; gauge.WidthRequest = 50; gauge.Value = 35; gauge.Thickness = 0.1; gauge.Min = 0; gauge.Max = 100; gauge.Direction = LinearGaugeDirection.Right; gauge.PointerColor = Color.Blue; //Create Ranges GaugeRange low = new GaugeRange(); GaugeRange med = new GaugeRange(); GaugeRange high = new GaugeRange(); //Customize Ranges low.Color = Color.Red; low.Min = 0; low.Max = 40; med.Color = Color.Yellow; med.Min = 40; med.Max = 80; high.Color = Color.Green; high.Min = 80; high.Max = 100; //Add Ranges to Gauge gauge.Ranges.Add(low); gauge.Ranges.Add(med); gauge.Ranges.Add(high); return gauge; } |
QuickStart.xaml
) to your Portable or Shared project and modify the <ContentPage>
tag to include Xuni reference as shown below:
XAML |
Copy Code |
---|---|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Appl.QuickStart" xmlns:xuni="clr-namespace:Xuni.Xamarin.Gauge;assembly=Xuni.Xamarin.Gauge"> |
<ContentPage></ContentPage>
tags and inside the <StackLayout></StackLayout>
tags, as shown below:
XAML |
Copy Code |
---|---|
<StackLayout> <xuni:XuniLinearGauge Value="35" Min="0" Max="100" Thickness="0.1" HeightRequest="50" WidthRequest="50" PointerColor="Blue" Direction="Right"> <xuni:XuniLinearGauge.Ranges> <xuni:GaugeRange Min="0" Max="40" Color="Red"/> <xuni:GaugeRange Min="40" Max="80" Color="Yellow"/> <xuni:GaugeRange Min="80" Max="100" Color="Green"/> </xuni:XuniLinearGauge.Ranges> </xuni:XuniLinearGauge> </StackLayout> |
App.cs
to open it.
App()
, set a new ContentPage
as the MainPage
and assign the control to the ContentPage
's Content
by invoking the method GetLinearGauge()
defined in the previous procedure, Step 1: Add a LinearGauge Control.
The following code shows the class constructor App()
after completing steps above.
C# |
Copy Code |
---|---|
public App() { // The root page of your application MainPage = new ContentPage { Content = QuickStart.GetLinearGauge() }; } |
App()
, set the Forms XAML Page QuickStart
as the MainPage
.
The following code shows the class constructor App()
, after completing this step.
C# |
Copy Code |
---|---|
public App() { // The root page of your application MainPage = new QuickStart(); } |
AppDelegate.cs
inside YourAppName.iOS project, to open it.
FinishedLaunching()
method.
C# |
Copy Code |
---|---|
Xuni.Xamarin.Gauge.Platform.iOS.Forms.Init(); |
MainPage.xml
.
MainPage.xml.cs
to open it.
C# |
Copy Code |
---|---|
Xuni.Xamarin.Gauge.Platform.WinPhone.GaugeRenderer.Init(); |