Xuni User Guide > Getting Started with Xuni > Adding Xuni Components using C# |
This topic demonstrates how to add a Xuni control to your app using C#. This is done in three steps:
Step 1: Add a new Class
Step 2: Add the Control
Class1.cs
to open it.
C# |
Copy Code |
---|---|
using Xuni.Xamarin.Gauge; using Xamarin.Forms; |
ReturnMyControl()
) with the control you want to add set as its return type.
The following example shows how to create an instance of the LinearGauge control and initialize it in the ReturnMyControl()
method definition.
C# |
Copy Code |
---|---|
public static XuniLinearGauge ReturnMyControl() { // 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; //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; } |
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 ReturnMyControl()
defined in the previous procedure, Step 2: Add a 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 = Class1.ReturnMyControl() }; } |
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(); |