We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind range collection to scale in Xamarin.Forms SfCircularGauge

Platform: Xamarin.Forms |
Control: SfCircularGauge |
Published Date: June 3, 2019 |
Last Revised Date: June 3, 2019

Circular gauge supports multiple ranges, and you can bind the ranges collection. This KB article explains the steps required to bind a property to the Ranges collection of SfCircularGauge.

 

Step 1: Create a ViewModel class and declare a property of type ObservableCollection<Range>. Define each range with the required properties and add it to the Ranges collection.

 

Refer to the following code sample for defining the collection property in view model.

 

C#:

 

     
        public ObservableCollection<Range> Ranges
        {
            get;
            set;
        }
 
        public ViewModel()
        {
            Ranges = new ObservableCollection<Range>();
         
            Range range = new Range();
            range.StartValue = 0;
            range.EndValue = 35;
            range.Offset = 0.7;
            range.Thickness = 30;
            range.Color = Color.FromHex("#F03E3E");
 
            Range range1 = new Range();
            range1.StartValue = 35;
            range1.EndValue = 75;
            range1.Offset = 0.7;
            range1.Thickness = 30;
            range1.Color = Color.FromHex("#FFDD00");
            
            Range range2 = new Range();
            range2.StartValue = 75;
            range2.EndValue = 100;
            range2.Offset = 0.7;
            range2.Thickness = 30;
            range2.Color = Color.FromHex("#27beb7");
 
            Ranges.Add(range);
            Ranges.Add(range1);
            Ranges.Add(range2);
        }
    }

 

Step 2: Set the BindingContext for gauge or the parent of gauge (e.g., ContentPage) as ViewModel. So, binding will work by taking that context.

 

Refer to the following code sample for setting binding context.

 

XAML:

 

<ContentPage.BindingContext>
        <local:ViewModel/>
</ContentPage.BindingContext>
 

 

Step 3: Bind the collection property defined in the ViewModel to the Ranges property of circular gauge’s scale as demonstrated in the following code sample.

 

XAML:

 

<gauge:SfCircularGauge>
 
     <gauge:SfCircularGauge.Scales>
 
            <gauge:Scale Ranges="{Binding Ranges}"/>
            
      </gauge:SfCircularGauge.Scales>
 
</gauge:SfCircularGauge>

 

Output

Xamarin.Forms SfCircularGauge Ranges

 

 

You can download the sample from the below link: Sample

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile