Slider SelectionStart SelectionEnd order bug

7 posts, 0 answers
  1. Jason Young
    Jason Young avatar
    4 posts
    Member since:
    Mar 2010

    Posted 06 Jul 2010 Link to this post

    I think I may have found a bug in the slider control. We're binding the SelectionStart and SelectionEnd properties to a model class in our DBML. The properties, let's call them "A" and "B" are in order, and correspond to the start and end in the slider. When we bind the control to a new instance of that class, "A" gets bound first, then "B". I have no control over the order.

    The problem is, when your control receives the first binding update (for "A"), it's can't be greater than "B", so it remains at zero. "B" then gets updated just fine.

    The end result  is that the selection start always ends up being 0.

    Is there a workaround? We've gone so far as to re-order the order of the DBML properties, but we're using WCF RIA, and the client side proxy is ordered alphabetically.
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 09 Jul 2010 Link to this post

    Hi Jason,

    With which version are you testing the project. We made some improvements to RadSlider and this issue might not be present anymore. Could you please download the latest internal build and test your application.

    Sincerely yours,
    Kiril Stanoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Jason Young
    Jason Young avatar
    4 posts
    Member since:
    Mar 2010

    Posted 09 Jul 2010 Link to this post

    We spent over $4,000 on these controls. I would appreciate it if you can see if it's still an issue, and if not, investigate WHICH version fixes it. We're about to release, and we need good information so that we can make an informed decision about what to do.
  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 09 Jul 2010 Link to this post

    Hello Jason,

    First of all, I'd like to apologize for the ambiguous answer.
    Internally, RadSlider makes coercion in the Loaded event handler of its SelectionStart and SelectionEnd properties.

    For example, imagine you create a RadSlider in code-behind:

    public MainPage()
    {
        InitializeComponent();
     
        RadSlider slider1 = new RadSlider();
        slider1.Minimum = 0;
        slider1.Maximum = 100;
        slider1.IsSelectionRangeEnabled = true;
        slider1.SelectionStart = 40;
        slider1.SelectionEnd = 60;
        this.LayoutRoot.Children.Add(slider1);
    }

    No matter that SelectionStart is set before SelectionEnd, such definition is valid since the slider is not loaded yet and its internal coerce mechanism have not yet passed.

    I assume that in your scenario, the slider is loaded and it is waiting for the WCF service to return values for SelectionStart and SelectionEnd. If SelectionStart arrives with a value (ex. 40) greater than SelectionEnd (ex. 10), SelectionStart will get set to 10 since it cannot be greater than SelectionEnd.
    One possible workaround is to set SelectionStart to be equal to the slider's Minimum and SelectionEnd to be equal to Maximum. This way, when SelectionStart arrives it will always be less than SelectionEnd and vice versa.

    Another way is to create a helper class that will stand between the WCF service and the slider:

    public class SliderHelper : INotifyPropertyChanged
    {
        private double selectionStart;
        private double selectionEnd;
        private bool notifySelectionStartChange;
        private double requestedSelectionStart;
     
        public double SelectionStart
        {
            get
            {
                return this.selectionStart;
            }
            set
            {
                if (this.selectionStart != value && value < this.selectionEnd)
                {
                    this.selectionStart = value;
                    this.OnPropertyChanged("SelectionStart");
                }
                else
                {
                    this.requestedSelectionStart = value;
                    this.notifySelectionStartChange = true;
                }
            }
        }
        public double SelectionEnd
        {
            get
            {
                return this.selectionEnd;
            }
            set
            {
                if (this.selectionEnd != value)
                {
                    this.selectionEnd = value;
                    this.OnPropertyChanged("SelectionEnd");
     
                    if (this.notifySelectionStartChange)
                    {
                        this.SelectionStart = this.requestedSelectionStart;
                        this.notifySelectionStartChange = false;
                    }
                }
            }
        }
     
        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    If you examine this class, you will see that when SelectionStart arrives and it is greater than SelectionEnd, the new SelectionStart value is kept in a variable and a flag is lifted. When SelectionEnd is set, the helper class checks if the flag is lifter and if it is lifted, it sets SelectionStart to the previously requested value.
    In the attached project, I've simulated a scenario where initially SelectionStart and SelectionEnd are 0.0.
    With a click of a button, a WCF service is called. I've made sure that SelectionEnd arrives after SelectionStart. With the help of the above class everything worked as expected.
    I am attaching my test project for further reference. Have a look at it and let me know if it works for you.

    Finally, I've discussed this scenario with my team and during Q3 2010 we will be working on implementing a functionality that will allow you do turn off the coerce mechanism and control SelectionStart and SelectionEnd yourself.

    Greetings,
    Kiril Stanoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Jason Young
    Jason Young avatar
    4 posts
    Member since:
    Mar 2010

    Posted 09 Jul 2010 Link to this post

    Thank you! This is what I was looking for. I'll let you know if I run into any problems getting a workaround in place.
  7. Tomáš Čeleda
    Tomáš Čeleda avatar
    15 posts
    Member since:
    Sep 2009

    Posted 17 Aug 2010 Link to this post

    Hello,
    I have encountered a similar problem. I didn't know that order of databinding matters.
    Problem is demonstrated in sample code below (tested with 2010 Q2 SP1):
    <StackPanel Orientation="Vertical">
                    <telerik:RadSlider IsSelectionRangeEnabled="True" Minimum="1" Maximum="10" SelectionEnd="{Binding End, Mode=TwoWay}" SelectionStart="{Binding Start, Mode=TwoWay}"
                                    Width="200" TickFrequency="1" />
                    <telerik:RadSlider IsSelectionRangeEnabled="True" Minimum="1" Maximum="10" SelectionStart="{Binding Start, Mode=TwoWay}" SelectionEnd="{Binding End, Mode=TwoWay}"
                                    Width="200" TickFrequency="1" />              
                    <TextBlock Text="{Binding Start}" />
                    <TextBlock Text="{Binding End}" />
                </StackPanel>
    There are two sliders bound to the same data model. The only difference is the order of binding SelectionStart and SelectionEnd. When the page is initially databound, the first slider has SelectionStart allways on zero, no matter what Start value in the model is. The second slider works as expected. I understand the coerce mechanism but it cause an inconsistency between slider and the model.
    I'm glad that it will be possible to switch off the coerce mechanism in Q3 version. When you will be modifying the control, you may consider this scenario.

    I have already resolved my problem thanks to this forum thread, so this is just an idea for future release.

    Regards
    Tomas Celeda

  8. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 19 Aug 2010 Link to this post

    Hello Tomáš Čeleda,

    Thank you for your suggestion. You are 100% correct that the order of setting properties in XAML shouldn't matter. I've created work item for this and will be considered for future implementation.
    Thank you once again.

    Kind regards,
    Miro Miroslavov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
DevCraft banner