This topic demonstrates how to add a Xamarin control to your app using C#. This is done in three steps:
Step 1: Add a new Class
Step 2: Add the Control
C# |
Copy Code
|
---|---|
using C1.Xamarin.Forms.Gauge; using Xamarin.Forms; |
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 C1LinearGauge ReturnMyControl() { // Instantiate LinearGauge and set its properties C1LinearGauge gauge = new C1LinearGauge(); 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; } |
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() }; } |
C# |
Copy Code
|
---|---|
C1.Xamarin.Forms.Gauge.Platform.iOS.C1GaugeRenderer.Init(); |
C# |
Copy Code
|
---|---|
C1.Xamarin.Forms.Gauge.Platform.UWP.C1GaugeRenderer.Init(); |