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

Slider changes SelectedStart to 0.

27 Answers 402 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Ruben Hakopian
Top achievements
Rank 1
Ruben Hakopian asked on 16 Sep 2010, 10:23 PM
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

27 Answers, 1 is accepted

Sort by
0
Miro Miroslavov
Telerik team
answered on 22 Sep 2010, 06:45 AM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 22 Sep 2010, 07:00 PM
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
0
Kiril Stanoev
Telerik team
answered on 28 Sep 2010, 08:38 AM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 28 Sep 2010, 10:19 PM
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"
                   />

.


0
Kiril Stanoev
Telerik team
answered on 30 Sep 2010, 02:30 PM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 30 Sep 2010, 06:24 PM
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
0
Kiril Stanoev
Telerik team
answered on 05 Oct 2010, 04:03 PM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 05 Oct 2010, 06:25 PM
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
0
Kiril Stanoev
Telerik team
answered on 06 Oct 2010, 07:59 AM
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
0
Kiril Stanoev
Telerik team
answered on 06 Oct 2010, 11:55 AM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 06 Oct 2010, 06:06 PM
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
0
Kiril Stanoev
Telerik team
answered on 07 Oct 2010, 10:05 AM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 07 Oct 2010, 07:28 PM
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
0
Kiril Stanoev
Telerik team
answered on 08 Oct 2010, 11:30 AM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 08 Oct 2010, 06:09 PM
Hi Kiril,

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

Thanks,
Ruben
0
Ruben Hakopian
Top achievements
Rank 1
answered on 12 Oct 2010, 11:29 PM
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
0
Kiril Stanoev
Telerik team
answered on 14 Oct 2010, 12:50 PM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 15 Oct 2010, 06:53 PM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 19 Oct 2010, 12:56 AM
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
0
Kiril Stanoev
Telerik team
answered on 19 Oct 2010, 08:06 AM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 24 Oct 2010, 01:10 PM
Hi Kiril,

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

Thanks,
Ruben
0
Ruben Hakopian
Top achievements
Rank 1
answered on 26 Oct 2010, 07:21 AM
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;
}


0
Kiril Stanoev
Telerik team
answered on 26 Oct 2010, 12:49 PM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 04 Nov 2010, 02:04 PM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 08 Nov 2010, 10:03 PM
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
0
Kiril Stanoev
Telerik team
answered on 09 Nov 2010, 11:41 AM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 09 Nov 2010, 06:01 PM
Thanks Kiril! This is exactly what I was looking for.
Tags
Slider
Asked by
Ruben Hakopian
Top achievements
Rank 1
Answers by
Miro Miroslavov
Telerik team
Ruben Hakopian
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Share this question
or