)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Declare the RangeSlider and bind the ValueProperty value with Label Text

Platform: Xamarin.Forms |
Control: SfRangeSlider |
Published Date: February 28, 2018 |
Last Revised Date: June 21, 2019

Syncfusion RangeSlider provides support for getting current vales of RangeSlider through binding.

 

To obtain current value of RangeSlider through binding:

 

Step 1:   Add require assemblies to get the view of RangeSlider.

Step 2:  Declare the two RangeSlider and binding the Value property values with another. That property’s values are from ViewModel class. Set the binding context of that page with the instance of ViewModel class.

 

The following code illustrates the way to achieve this method.

 

XAML code to set Custom filter:

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  xmlns:local="clr-namespace:RangeSliderSample"
  xmlns:range="clr-namespace:Syncfusion.SfRangeSlider.XForms;assembly=Syncfusion.SfRangeSlider.XForms"
  x:Class="RangeSliderSample.RangeSliderSamplePage">
 
<Grid HorizontalOptions="CenterAndExpand"
      VerticalOptions="CenterAndExpand" >
 
  <Grid.RowDefinitions>
    <RowDefinition Height="100"/>
    <RowDefinition Height="50"/>
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="100"/>
    <ColumnDefinition Width="1*"/>
  </Grid.ColumnDefinitions>
  <Label Grid.Row="0"
          Grid.Column="0"
          HorizontalTextAlignment="End"
          VerticalTextAlignment="Center"
          Text="Enter a Score"
          FontSize="Medium"
          TextColor="Black"/>
  <range:SfRangeSlider x:Name="rangeSlider"
                        Grid.Row="0"
                        Grid.Column="1"
                        Orientation="Horizontal"
                        HeightRequest="80"
                        ShowRange="false"
                        Maximum="10"
                        Minimum="1"
    ShowValueLabel="true"
      ValuePlacement="TopLeft"
                        TickPlacement="BottomRight"
                        TickFrequency="1"
            
                        StepFrequency="1"
                        SnapsTo="StepValues"
                        LabelColor="Black"
                        KnobColor="Blue"
                        TrackColor="Green"
                        Value="{Binding Value1, Mode=TwoWay}"/>
  <Label Text="Current Value" Grid.Row="1" Grid.Column="0" HorizontalTextAlignment="End"
          VerticalTextAlignment="Center"/>
  <Label Text="{Binding Value1, Mode=TwoWay}" VerticalOptions="Center" HorizontalOptions="Center"
          Grid.Row="1"
          Grid.Column="1"
          TextColor="Black"
              />
</Grid>
</ContentPage>
 

 

Code behind code:

namespace RangeSliderSample
{
public partial class RangeSliderSamplePage : ContentPage
{
    MainPageViewModel model;
 
    public RangeSliderSamplePage()
    {
        InitializeComponent();
        model = new MainPageViewModel();
        this.BindingContext = model;
    }
}
public class MainPageViewModel : INotifyPropertyChanged
{
    double value1;
    public double Value1
    {
        get { return value1; }
        set
        {
            if (value1 != value)
            {
                value1 = value;
                OnPropertyChanged("Value1");
            }
        }
    }
 
    public event PropertyChangedEventHandler PropertyChanged;
 
    protected virtual void OnPropertyChanged(string propertyName)
    {
        var changed = PropertyChanged;
        if (changed != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
}
 

 

 

Image after binding the Value:

Binding in SfRangeSlider

 

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
Live Chat Icon