Articles in this section
Category / Section

Declare the RangeSlider and bind the ValueProperty value with Label Text

1 min read

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

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied