This is a migrated thread and some comments may be shown as answers.

TrackBar - range mode - binding

1 Answer 125 Views
TrackBar
This is a migrated thread and some comments may be shown as answers.
Bambis
Top achievements
Rank 1
Bambis asked on 19 Mar 2019, 08:40 PM

In simple mode, binding works correctly. 

.............. 

//Define property

private float start;
    public float Start
    {
        get => start;
        set
        {
            if (value == Start) return;
            start = value;
            OnPropertyChanget("Start");
        }
    }

..............................................

//Binding

  radTrackBar1.DataBindings.Add("Value", Data, "Start", true, DataSourceUpdateMode.OnPropertyChanged);
  radTrackBar2.DataBindings.Add("Value", Data, "Start", true, DataSourceUpdateMode.OnPropertyChanged);

.........................................................

How can I use binding in range mod?

   radTrackBar1.Ranges[0].Start = 1;
   radTrackBar1.Ranges[0].End = 50;
   radTrackBar2.Ranges[0].Start = 1;
   radTrackBar2.Ranges[0].End = 50;

//Define property ??????????????????????

//Binding ??????????????????????????

Thanks!

 

 

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 20 Mar 2019, 07:28 AM
Hi Peter,

Currently, It is not possible to use simple data binding with the range mode, we have a feature request that will allow this. You can track its progress, subscribe to status changes and add your comment to it here: ADD. RadTrackBar - new event notifying that a range start or end has changed.

At this point, you can use the events to synchronize the properties. Here is a complete example that shows this:
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
    MyClass data;
    public RadForm1()
    {
        InitializeComponent();
 
        this.radTrackBar1.Ranges[0].Start = 2;
        this.radTrackBar1.Ranges[0].End = 5;
 
        data = new MyClass() { Start = 5, End = 10 };
        data.PropertyChanged += Data_PropertyChanged;
        this.radTrackBar1.Ranges.CollectionChanged += Ranges_CollectionChanged;
 
 
    }
    void Ranges_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
    {
        if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.ItemChanged)
        {
            foreach (object item in e.NewItems)
            {
                TrackBarRange range = item as TrackBarRange;
                if (range != null)
                {
                    data.Start = range.Start;
                    data.End = range.End;
 
                }
            }
        }
    }
    private void Data_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        var data = sender as MyClass;
        radTrackBar1.Ranges[0].Start = data.Start;
        radTrackBar1.Ranges[0].End = data.End;
    }
  
}
class MyClass : INotifyPropertyChanged
{
    private float start;
    private float end;
    public float Start
    {
        get => start;
 
        set
        {
            if (value == start)
            {
                return;
            }
            start = value;
            OnPropertyChanged("Start");
        }
    }
    public float End
    {
        get => end;
 
        set
        {
            if (value == end)
            {
                return;
            }
            end = value;
            OnPropertyChanged("End");
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;
    public void OnPropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
TrackBar
Asked by
Bambis
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or