Slider changes SelectedStart to 0.

28 posts, 0 answers
  1. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 16 Sep 2010 Link to this post

    Hi,

    I'm using RadSlider in range mode and doing TwoWay databinding on SelectionStart and StelectionEnd properties. I set the values within Minimum/Maximum range. However, the very first time during dialog load the Slider coerces SelectionStart value to 0. 

    This is the slider code:
    <RadSlider Minimum="-10" Maximum="50"
               SelectionStart="{Binding Path=CappedMinBitrate, Mode=TwoWay}" 
               SelectionEnd="{Binding Path=CappedMaxBitrate, Mode=TwoWay}"
               IsSelectionRangeEnabled="True"
               />

    Initial valud of SelectionStart is set to 3.0. In the attached screenshot you can see how the value is being set to 0 from CoerceSelectionStart method.

    Please let me know if I'm doing something wrong or there is a way to fix it.

    Thank you,
    Ruben
  2. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 22 Sep 2010 Link to this post

    Hi Ruben Hakopian,

     Please find the attached workaround project and let me know if this is working for you. However I've created work item for this, because it's a bug. (you can find it after a while and track it's progress - "Slider: SelectionStart, SelectionEnd doesn't work with Binding."). 
    Sorry for any inconvenience. 

    Greetings,
    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 22 Sep 2010 Link to this post

    Hi Miroslav,

    For some reason this workaround does not make any difference in my application.
    The value of property bound to SelectionStart is being set to Minimum value.

    I looked to your sample application, and the behavior I'm experiencing does not happen
    on your example.

    Thanks,
    Ruben
  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 28 Sep 2010 Link to this post

    Hi Ruben,

    Will it help if you do the following workaround:

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.DataContext = new Context();
     
            InitializeComponent();
     
            Loaded += new RoutedEventHandler(MainWindow_Loaded);
        }
     
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            slider.UpdateLayout();
        }
    }

    Let me know if this helps. If not, could you please isolate the issue in a separate application and send it to us. This way we will be better able to assist you.

    All the best,
    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. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 28 Sep 2010 Link to this post

    Hi Kirill,

    Unfortunately workaround does not help to me. I'm using version# "2010.2.812.35".
    It looks like the problem is because of binding to Maximum/Minimum values. Sometimes,
    when binding to Minimum/Maximum values application crashes with StackOverflowException.

    Seems lithe the sliders stars validating SelectionStart/SelectionEnd values whenever the property is set or bound, and it does not wait for other properties (like Minimum/Maximum)  to be set first before doing validations and coercing.

    Please check this sample below.

    Thank you,
    Ruben.

    public class ViewModel : System.ComponentModel.INotifyPropertyChanged
    {
        private double _minimum;
        private double _maximum;
        private double _start;
        private double _end;
     
        public double Minimum
        {
            get { return _minimum; }
            set
            {
                if (_minimum == value)
                    return;
                _minimum = value;
                OnPropertyChanged("Minimum");
            }
        }
     
        public double Maximum
        {
            get { return _maximum; }
            set
            {
                if (_maximum == value)
                    return;
                _maximum = value;
                OnPropertyChanged("Maximum");
            }
        }
     
        public double Start
        {
            get { return _start; }
            set
            {
                if (_start == value)
                    return;
                _start = value;
                OnPropertyChanged("Start");
            }
        }
     
        public double End
        {
            get { return _end; }
            set
            {
                if (_end == value)
                    return;
                _end = value;
                OnPropertyChanged("End");
            }
        }
     
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
     
        private void OnPropertyChanged(string propertyName)
        {
            System.ComponentModel.PropertyChangedEventHandler deleg = PropertyChanged;
            if (deleg != null)
                deleg(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }


    void Window1_Loaded(object sender, RoutedEventArgs e)
    {
        var vm = new ViewModel();
         
        vm.Minimum = 0;
        vm.Maximum = 50;
     
        vm.Start = 20;
        vm.End = 40;
     
        this.DataContext = vm;
    }


    <telerik:RadSlider VerticalAlignment="Top"
                       Minimum="{Binding Path=Minimum}"
                       Maximum="{Binding Path=Maximum}"
                       SelectionStart="{Binding Path=Start, Mode=TwoWay}"
                       SelectionEnd="{Binding Path=End, Mode=TwoWay}"
                       IsSelectionRangeEnabled="True"
                       />

    .


  7. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 30 Sep 2010 Link to this post

    Hi Ruben,

    I am not sure whether I am doing something wrong, but I moved whatever was in the Loaded event handler to the constructor and everything worked like a charm. I did not experience any stack overflows or any wrong behavior. I ran the application more than 10 times. A screencast can be found here. I am also attaching a sample project with your code. Run at your end and let me know if you manage to reproduce the issue.

    Best wishes,
    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
  8. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 30 Sep 2010 Link to this post

    Hi Kirill,

    It sounds unbelievable, but it makes a difference if you create the view model in loaded event and constructor.
    Please take a look to my sample application from here http://rubenhak.com/RadSliderTest.zip

    There are 2 sliders in the application.
    *) If you uncomment first one you should see that SelectionStart is set to 0.
    *) If you uncomment second one you should see that StackOverflow exception.

    Please let me know how it works.

    Thank you very much!
    Ruben
  9. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 05 Oct 2010 Link to this post

    Hi Ruben,

    Indeed it matters where you set the DataContext. I will further investigate why this happens but for the moment my suggestion is to set the DataContext before the InitializeComponent() method as shown in the sample attached.

    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
  10. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 05 Oct 2010 Link to this post

    Hi Kiril,

    Unfortunately my control gets initialized long before ViewModel object is created and therefore being data bound. 

    Please kindly let me know if there is a chance for you guys to have a special internal build which solved this issue.

    Thank you!
    Ruben
  11. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 06 Oct 2010 Link to this post

    Hi Ruben,

    We will do our best to fix this issue with this week's internal build but I cannot guarantee this with 100% certainty. However, if the fix does not get included in this week's internal build it will definitely be part of next week's internal build. Is this ok with you?

    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
  12. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 06 Oct 2010 Link to this post

    Hello Ruben,

    Couple of quick questions as I am starting to work on a fix for the issue. Currently RadSlider validates the values for Minimum, Maximum, SelectionStart and SelectionEnd in its Loaded event handler. That is why setting the DataContext in the Loaded event of the Window gives undesired results.
    In your scenario - is it OK if you create  the DataContext in the constructor of the MainWindow (after InitializeComponent)?

    public Window1()
    {
        InitializeComponent();
        var vm = new ViewModel();
     
        vm.Minimum = 30;
        vm.Maximum = 50;
     
        vm.Start = 20;
        vm.End = 40;
     
        this.DataContext = vm;
    }

    ...or do you insist on setting the DataContext in the Loaded event handler?

    public Window1()
    {
        InitializeComponent();
        Loaded += new RoutedEventHandler(Window1_Loaded);
    }
     
    void Window1_Loaded(object sender, RoutedEventArgs e)
    {
        var vm = new ViewModel();
     
        vm.Minimum = 30;
        vm.Maximum = 50;
     
        vm.Start = 20;
        vm.End = 40;
     
        this.DataContext = vm;
    }

    In my opinion, the correct approach is to set the DataContext right after the InitializeComponent().
    If setting the DataContext after InitializeComponent (as shown on the green code snippet) is fine with you, then this week's internal build should solve your issues. Let me know what you think.

    All the best,
    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
  13. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 06 Oct 2010 Link to this post

    Hi Kirill,

    We are using a M-V-VM self assembling GUI framework, which first instantiates user control and then the DataContext is being set. Our user controls do not have much knowledge about the object that will be data bound. So there is no way we can specify the data context after InitializeComponent.

    The DataContext is usually being set after the control is instantiated and loaded. 

    My preference is to have an ability to set the DataContext at any given place and time, and control should pick it up correctly. This is how it works for all of standard WPF control, and any other Telerik controls.

    Just one more thing that might help you this issue. Whenever binding Minimum,  Maximum and Value properties, the sequence of values being set becomes very important. For example. If Minumum=10, Maximum=20, Value = 15  and I want  to set Value = 30 and Maximum=50. If the slider sets Value first, it might be coerced to 20 and the value would remain 20. Maybe validations should be performed after these fields are being set and validate all at once. Just some ideas.

    I appreciate your willingness to have this thing done!

    Thanks,
    Ruben
  14. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 07 Oct 2010 Link to this post

    Hi Ruben,

    This is a work-in-progress version of the binaries that are about to be released with this or next week's internal build. Give it a try and let me know if it works for you.

    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
  15. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 07 Oct 2010 Link to this post

    Hi Kiril,

    Thanks for fixing it so quickly. I tried your sample, it looks perfect.
    However I cannot use this DLL to test my app, since we are using other libraries (Telerik.Navigation, .Grid, ... etc) and just replacing Telerik.Controls.dll does not work. Can you please send me other DLLs as well?

    Thank you,
    RUben
  16. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 08 Oct 2010 Link to this post

    Hello Ruben,

    The fix will be included in this week's internal build. Give it a try and let me know how it goes. If you experience any issues, we are having a Beta release next week, so let me know if it needs further fixing.

    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
  17. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 08 Oct 2010 Link to this post

    Hi Kiril,

    Sounds great!
    I will try this week's internal build.

    Thanks,
    Ruben
  18. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 12 Oct 2010 Link to this post

    Hi Kiril,

    This version is definitely an improvement! 
    SelectionStart value is not being set to 0 anymore. 

    However, the thumb position is set to 0 the first time it is
    rebound (even though the value SelectionStart is not 0).
    Tried to call UpdateLayout(); as you suggested before, but
    it does not fix the layout.

    Thanks,
    Ruben
  19. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 14 Oct 2010 Link to this post

    Hello Ruben,

    I've made additional fixes to RadSlider. Please have a look at this work-in-progress project. It includes fixes for the rendering issue as well as a try/catch block for the LoadContent method. Play around with the project and let me know if you encounter any additional issues. If everything is all right, the fixes will be included in tomorrow's internal build. I've also updated your Telerik points.

    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
  20. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 15 Oct 2010 Link to this post

    Hi Kirill,

    Thank you for these fixes. This sample looks good to me.
    In order to verify in my application, I will need to have 
    full internal build package. 

    Will verify on monday and will let you know.

    Thank you,
    Ruben
  21. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 18 Oct 2010 Link to this post

    Hi Kiril,

    I tried to use the latest internal build, but still getting exception when changing the DataContext.
    Looked to LoadTemplate function body using .NET Reflector and it does not seem that this 
    function is protected by try\catch. 

    Please look to exception trace below: 

    at Telerik.Windows.Controls.RadTickBar.LoadTemplate(Double tickValue)
    at Telerik.Windows.Controls.RadTickBar.CreateTick(Double tickValue)
    at Telerik.Windows.Controls.RadTickBar.DrawTicks()
    at Telerik.Windows.Controls.RadSlider.RedrawTicks()
    at Telerik.Windows.Controls.RadSlider.OnMaximumChanged(Double oldMaximum, Double newMaximum)
    at System.Windows.Controls.Primitives.RangeBase.OnMaximumChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
    at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
    at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
    at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
    at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)
    at System.Windows.Data.BindingExpression.Invalidate(Boolean isASubPropertyChange)


    Thank you,
    Ruben
  22. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 19 Oct 2010 Link to this post

    Hi Ruben,

    Unfortunately the fixes were not included in the last internal build. They will be included in this week's internal build however. Let me know if this time frame is ok for you.

    Kind regards,
    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
  23. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 24 Oct 2010 Link to this post

    Hi Kiril,

    I will try this weeks build and will let you know how it works.

    Thanks,
    Ruben
  24. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 26 Oct 2010 Link to this post

    Hi Kiril,

    This exception still happens when changing the DataContext. I'm looking to disassembly and speculating if it is possible that 
    this.TickTemplateSelector.SelectTemplate(tickValue + this.Minimum, null) is null or DefaultTickTemplate can be null.
    Maybe there should be another condition to check if DefaultTickTemplate is not null? 

    Can you guys add debug output in exception handlers so we can get an idea in which block does the exception happen?

    Thank you very much!

    Ruben

    [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
    private FrameworkElement LoadTemplate(double tickValue)
    {
        FrameworkElement element = null;
        if (this.TickTemplate != null)
        {
            try
            {
                element = this.TickTemplate.LoadContent() as FrameworkElement;
            }
            catch
            {
            }
        }
        else if (this.TickTemplateSelector != null)
        {
            element = this.TickTemplateSelector.SelectTemplate(tickValue + this.Minimum, null).LoadContent() as FrameworkElement;
        }
        else
        {
            try
            {
                element = this.DefaultTickTemplate.LoadContent() as FrameworkElement;
            }
            catch
            {
            }
        }
        element.DataContext = tickValue + this.Minimum;
        return element;
    }


  25. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 26 Oct 2010 Link to this post

    Hello Ruben,

    I managed to reproduce the issue by editing the style of RadSlider and removing this piece of code:

    <DataTemplate x:Key="VerticalTickTemplate">
        <Grid x:Name="RootElement" ToolTip="{Binding}">
            <Rectangle Fill="Black" Height="1" Width="5" />
        </Grid>
    </DataTemplate>
    <DataTemplate x:Key="HorizontalTickTemplate">
        <Grid x:Name="RootElement" ToolTip="{Binding}">
            <Rectangle Fill="Black" Height="5" Width="1" />
        </Grid>
    </DataTemplate>

    I assume you have done something similar. Anyway, I've modified RadSlider so it checks if the above tick templates exist. I'm attaching a work-in-progress version of the Telerik.Windows.Controls.dll. Give it a try and let me know if you still manage to reproduce the issue.

    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
  26. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 04 Nov 2010 Link to this post

    Hi Kiril,

    Sorry for late reply. Unfortunately, I cannot try DLL you sent cause I'm using other telerik dlls and replacing just one does not work.
    I'm looking forward to get the latest internal build and try your fix than.

    Thanks,
    Ruben
  27. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 08 Nov 2010 Link to this post

    Hi Kiril,

    I tried latest build and looks like template exception issue is solved and I can successfully change the DataContext.
    However, I noticed another issue with latest build. When using selection range it is not possible to scroll the SelectionEnd lower then SelectionStart, and SelectionStart upper beyond SelectionEnd. Visually thumbs stay in their place, but property values get corrupted. The rule SelectionStart <= SelectionEnd is not guaranteed anymore. 

    Please try this sample:

    <Window x:Class="WpfApplication2.MainWindow"
            xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" Title="MainWindow"
            Height="350" Width="525">
        <Window.Resources>
            <DataTemplate x:Key="TickTemplate">
                <Grid>
                    <TextBlock Text="{Binding}" />
                </Grid>
            </DataTemplate>
        </Window.Resources>
        <Grid >
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
             
            <telerik:RadSlider x:Name="slider" VerticalAlignment="Center" Margin="10" Minimum="-10" Maximum="10" TickFrequency="1"
                               TickPlacement="BottomRight" SelectionStart="{Binding Path=Start, Mode=TwoWay}"
                               SelectionEnd="{Binding Path=End, Mode=TwoWay}" IsSelectionRangeEnabled="True"
                               TickTemplate="{StaticResource TickTemplate}" />
     
            <StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center"
                        TextElement.FontSize="24">
                <TextBlock Text="Start: " />
                <TextBlock Text="{Binding Path=Start, Mode=OneWay}" />
            </StackPanel>
     
            <StackPanel Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center"
                        TextElement.FontSize="24">
                <TextBlock Text="End: " />
                <TextBlock Text="{Binding Path=End, Mode=OneWay}" />
            </StackPanel>
        </Grid>
    </Window>


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.ComponentModel;
     
    namespace WpfApplication2
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
     
                this.DataContext = new Context
                {
                    Start = 2,
                    End = 5
                };
            }
        }
     
        public class Context : INotifyPropertyChanged
        {
            private int start, end;
     
            public int Start
            {
                get
                {
                    return this.start;
                }
                set
                {
                    this.start = value;
                    OnPc("Start");
                }
            }
     
            public int End
            {
                get
                {
                    return this.end;
                }
                set
                {
                    this.end = value;
                    OnPc("End");
                }
            }
     
            public event PropertyChangedEventHandler PropertyChanged;
     
            private void OnPc(string propName)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(propName));
                }
            }
        }
    }


    Thank you,
    Ruben
  28. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 09 Nov 2010 Link to this post

    Hello Ruben,

    Thank you for reporting this issue. I've managed to reproduce it and a fix will be available with our official Q3  2010 release which is scheduled for this week. I'm attaching a project with a work-in-progress binaries along with your scenario. Give it a try and let me know how it works. I've also updated your Telerik points accordingly. 

    Regards,
    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
  29. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 09 Nov 2010 Link to this post

    Thanks Kiril! This is exactly what I was looking for.
Back to Top
UI for WPF is Visual Studio 2017 Ready