Selection start/end jump when changing binding value in codebehind

6 posts, 0 answers
  1. Derek
    Derek avatar
    9 posts
    Member since:
    Nov 2011

    Posted 09 Nov 2011 Link to this post

    I am using the RadSlider in Silverlight with properties set to -

    SelectionStart="{Binding Rules.Min, Mode=TwoWay}"
    SelectionEnd="{Binding Rules.Max, Mode=TwoWay}"
    TickFrequency="5"
    IsSnapToTickEnabled="True"
    IsSelectionRangeEnabled="True"

    My issue is when I change the SelectionEnd from 20 to 50 and then "cancel" that value setting it back to 20 in the codebehind the next time I move the end thumb it jumps back up to 50 when I would expect it to go to 25.  I have a sample project I can attach but don't see a place for it.  I am using version 2011.2.1010.1040 of Telerik.Windows.Controls.
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 14 Nov 2011 Link to this post

    Hello Derek,

     Could you please try to use the Selection property (of type SelectionRange<double>) of the the RadSlider, instead of SelectionStart and SelectionEnd ? We recently fixed some issues when binding the SelectionStart and SelectionEnd, but we highly suggest you to use the Selection property instead. With the upcoming Q3 Release , we will introduce these fixes among with documentation describing how to bind and use the Selection successfully.

    Best wishes,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Derek
    Derek avatar
    9 posts
    Member since:
    Nov 2011

    Posted 15 Nov 2011 Link to this post

    Hey Petar,

    I tried binding to the Selection and it still behaves the same. I have supplied the code for my sample project so you can see what I am trying to do.

    <Grid x:Name="LayoutRoot" Background="White">
            <StackPanel x:Name="Panel" x:FieldModifier="public">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition Width="300" />
                    </Grid.ColumnDefinitions>
     
                    <Grid.RowDefinitions>
                        <RowDefinition Height="50"/>
                    </Grid.RowDefinitions>
                    <Button Content="Copy Old Value" Click="Button_Click" Grid.Column="0"/>
                    <telerik:RadSlider x:Name="Slider"
                                x:FieldModifier="public"
                                TickPlacement="BottomRight"
                                VerticalAlignment="Bottom"
                                SelectionStart="0"
                                Selection="{Binding Rules.Selection, Mode=TwoWay}"
                                TickFrequency="5"
                                IsSnapToTickEnabled="True"
                                IsSelectionRangeEnabled="True"
                                Minimum="0" Maximum="50"
                                Margin="10,0,10,0"
                                   Grid.Column="2">
                        <telerik:RadSlider.TickTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding}" FontSize="10" />
                                </StackPanel>
                            </DataTemplate>
                        </telerik:RadSlider.TickTemplate>
                    </telerik:RadSlider>
                </Grid>
            </StackPanel>
        </Grid>

    public partial class MainPage : UserControl, INotifyPropertyChanged
        {
            private Weight weightVO = new Weight();
            public Weight WeightVO
            {
                get { return weightVO; }
                set { weightVO = value; }
            }
     
            public MainPage()
            {
                InitializeComponent();
                Panel.DataContext = WeightVO.Temp;
            }
     
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                WeightVO.SetTempToCurrent();
            }
     
            public event PropertyChangedEventHandler PropertyChanged;
            protected void OnPropertyChanged(string name)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(name));
                }
            }
        }

    public class Weight
        {
            private Search current = DefaultSearch();
            public Search Current
            {
                get { return current; }
                set { current = value; }
            }
     
            private Search temp = DefaultSearch();
            public Search Temp
            {
                get { return temp; }
                set { temp = value; }
            }
     
            public void SetTempToCurrent()
            {
                Temp.CopyValues(Current);
            }
     
            public static Search DefaultSearch()
            {
                Rules rules = new Rules() {End = 5d, Selection = new SelectionRange<double>(0, 5)};
                return new Search() { Rules = rules };
            }
        }

    public class Search : INotifyPropertyChanged
        {
            private Rules rules = new Rules();
            public Rules Rules
            {
                get { return rules; }
                set
                {
                    rules = value;
                    OnPropertyChanged("Rules");
                }
            }
     
            public void CopyValues(Search search)
            {
                Rules = new Rules(search.Rules);
            }
     
            public event PropertyChangedEventHandler PropertyChanged;
            protected void OnPropertyChanged(string name)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(name));
                }
            }
        }


    public class Rules : INotifyPropertyChanged
        {
            private double end;
            public double End
            {
                get { return end; }
                set
                {
                    end = value;
                    OnPropertyChanged("End");
                }
            }
     
            private SelectionRange<double> selection = new SelectionRange<double>(0, 5);
            public SelectionRange<double> Selection
            {
                get { return selection; }
                set
                {
                    selection = value;
                    End = selection.End;
                    OnPropertyChanged("Selection");
                }
            }
     
     
            public Rules() { }
     
            public Rules(Rules rules)
            {
                end = rules.end;
                     selection = rules.selection;
            }
     
            public event PropertyChangedEventHandler PropertyChanged;
            protected void OnPropertyChanged(string name)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(name));
                }
            }
        }
  5. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 18 Nov 2011 Link to this post

    Hello Derek,

    Thank you for providing the code snippet. We have managed to create a sample application based on the code snippets. Is it possible to send us some steps to reproduce the issue using this code and what is the expected result. Thank you.

    All the best,
    Alex Fidanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Derek
    Derek avatar
    9 posts
    Member since:
    Nov 2011

    Posted 18 Nov 2011 Link to this post

    Hi Alex,

    Steps to reproduce:
    Move end slider from 5 to 30
    Click Copy Old Value Button - should cause end slider to move back to 5
    Move end slider again

    Actual Results
    End slider jumps  back to 30

    Expected 
    End slider jumps to 10
  7. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 21 Nov 2011 Link to this post

    Hello Derek,

    Thank you for reporting this. We have acknowledged this as an issue in the slider control. I have logged this in our PITS unde "Incorrect range after changing the value and dragging a thumb" and you will be able to track it in the system within one day. I have also updated your Telerik points.

    All the best,
    Alex Fidanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner