Not able to set SelectionStart and SelectionEnd

2 posts, 0 answers
  1. Tarun Yadav
    Tarun Yadav avatar
    6 posts
    Member since:
    Oct 2009

    Posted 15 Oct 2009 Link to this post


    I am using RADSlider using DataTemplates. These data templates are applied based on the selected item in a combo box. (Combo Box has "Hour", "Day" and "Week" values. Based on the item i show the tick labels as dates.
    Template looks like below:




    <DataTemplate x:Name="DailyTickTemplate">  
                        <RowDefinition Height="Auto"/>  
                        <RowDefinition Height="Auto"/>  
                    <Rectangle Grid.Row="0" Width="2" Height="6" Fill="White" Margin="0,2,0,0" VerticalAlignment="Top" /> 
                    <TextBlock Grid.Row="1" Text="{Binding Converter={StaticResource DailyConverter}}" FontSize="8" Foreground="White"/>  

    The Problem is: When I try to set the Selection Start and Selection End of Slider from code on combobox selected item changed event, i can't do that.
    Irrespective of what is assigned to selection start and selection end, it assumes some wierd values.





  2. Kiril Stanoev
    Kiril Stanoev avatar
    1512 posts

    Posted 19 Oct 2009 Link to this post

    Hi Tarun,

    This is a known side effect of SelectionStart and SelectionEnd properties of RadSlider. Imagine you have a slider that initially has SelectionStart set to 0.4 and SelectionEnd set to 0.6. In the click event handler of some button, you try to reset SelectionStart and SelectionEnd by doing the following:

    slider.SelectionStart = 0.7;
    slider.SelectionEnd = 0.8;

    The problem with the above is that when you say slider.SelectionStart = 0.7;, the coerce mechanism of the slider will be triggered. These coerces will evaluate the incoming value (0.7) and check if it is less than the Minimum, greater than the Maximum or greater than the SelectionEnd. SelectionEnd was initially 0.6
    and we are now trying to set SelectionStart to 0.7. As a result of the coerces, the new SelectionStart will be 0.6 and the new SelectionEnd will be 0.8.
    As a workaround, I'd suggest you first reset the SelectionStart and SelectionEnd, and then first assign the SelectionEnd and then the SelectionStart:

    // reset
    slider.SelectionStart = 0.0;
    slider.SelectionEnd = 0.0;
    // assign new values, order is important
    slider.SelectionEnd = newSelectionEnd;
    slider.SelectionStart = newSelectionStart;

    Give it a try and let me know how it works for you.

    Kiril Stanoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top