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

Problem with RadSlider and negative values...

1 Answer 120 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 24 Nov 2010, 11:02 PM

Hello,

In my app, I attempt to create a RadSlider with the following attributes:
   IsSelectionRangeEnabled="True"
   Minimum="-100"
   Maximum="100"
   SelectionStart="-38"
   SelectionEnd="71"

   
I have come across some strange behaviour...

If I set the values explicitly, it seems to work fine.  If I set the values through binding, it doesn't work properly unless i have a particular order in my xaml, or specify a fallback value.  Below you'll find sample code which displays four sliders.  The first, third and fourth seem to work properly.  The second does not - it seems to lose the positive values.  I have also attached a picture of what I see when I execute this code.  The only difference between the second and third sliders is the ordering of the xaml...

<UserControl    x:Class="SilverlightApplication118.MainPage"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                Width="400"
>
  
    <StackPanel Orientation="Vertical" Background="White">
          
        <Grid Background="Pink" Margin="5">
                  
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
                  
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="30" />
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="30" />
            </Grid.ColumnDefinitions>
                  
            <telerik:RadSlider x:Name="sldr1" Grid.Row="0" Grid.Column="1" IsSelectionRangeEnabled="True" Minimum="-100" Maximum="100" SelectionStart="-38" SelectionEnd="71" />
            <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding SelectionStart, ElementName=sldr1, StringFormat='\{0:n0\}'}" HorizontalAlignment="Center"/>
            <TextBlock Grid.Row="0" Grid.Column="2" Text="{Binding SelectionEnd, ElementName=sldr1, StringFormat='\{0:n0\}'}" HorizontalAlignment="Center" />
  
        </Grid>
          
        <Grid Background="YellowGreen" Margin="5">
              
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
                  
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="30" />
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="30" />
            </Grid.ColumnDefinitions>
                  
            <telerik:RadSlider x:Name="sldr2" Grid.Row="0" Grid.Column="1" IsSelectionRangeEnabled="True" Minimum="{Binding Minimum}" Maximum="{Binding Maximum}" SelectionStart="{Binding SelectionStart, Mode=TwoWay}" SelectionEnd="{Binding SelectionEnd, Mode=TwoWay}" />
            <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding SelectionStart, ElementName=sldr2, StringFormat='\{0:n0\}'}" HorizontalAlignment="Center"/>
            <TextBlock Grid.Row="0" Grid.Column="2" Text="{Binding SelectionEnd, ElementName=sldr2, StringFormat='\{0:n0\}'}" HorizontalAlignment="Center" />
  
        </Grid
          
        <Grid Background="Bisque" Margin="5">
                  
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
                  
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="30" />
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="30" />
            </Grid.ColumnDefinitions>
                  
            <telerik:RadSlider x:Name="sldr3" Grid.Row="0" Grid.Column="1" IsSelectionRangeEnabled="True" Maximum="{Binding Maximum}" Minimum="{Binding Minimum}" SelectionStart="{Binding SelectionStart, Mode=TwoWay}" SelectionEnd="{Binding SelectionEnd, Mode=TwoWay}" />
            <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding SelectionStart, ElementName=sldr3, StringFormat='\{0:n0\}'}" HorizontalAlignment="Center"/>
            <TextBlock Grid.Row="0" Grid.Column="2" Text="{Binding SelectionEnd, ElementName=sldr3, StringFormat='\{0:n0\}'}" HorizontalAlignment="Center" />
  
        </Grid
          
        <Grid Background="Plum" Margin="5">
                  
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
                  
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="30" />
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="30" />
            </Grid.ColumnDefinitions>
              
            <telerik:RadSlider x:Name="sldr4" Grid.Row="0" Grid.Column="1" IsSelectionRangeEnabled="True" Minimum="{Binding Minimum, FallbackValue=0}" Maximum="{Binding Maximum, FallbackValue=10}" SelectionStart="{Binding SelectionStart, Mode=TwoWay, FallbackValue=3}" SelectionEnd="{Binding SelectionEnd, Mode=TwoWay, FallbackValue=7}" />
            <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding SelectionStart, ElementName=sldr4, StringFormat='\{0:n0\}'}" HorizontalAlignment="Center"/>
            <TextBlock Grid.Row="0" Grid.Column="2" Text="{Binding SelectionEnd, ElementName=sldr4, StringFormat='\{0:n0\}'}" HorizontalAlignment="Center" />
  
        </Grid
          
    </StackPanel>
      
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
  
namespace SilverlightApplication118
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            // Required to initialize variables
            InitializeComponent();
              
            this.sldr2.DataContext = new ToleranceDataObject() { Minimum = -100, Maximum = 100, SelectionStart = -38, SelectionEnd = 71 };
              
            this.sldr3.DataContext = new ToleranceDataObject() { Minimum = -100, Maximum = 100, SelectionStart = -38, SelectionEnd = 71 };
              
            this.sldr4.DataContext = new ToleranceDataObject() { Minimum = -100, Maximum = 100, SelectionStart = -38, SelectionEnd = 71 };
              
        }
    }
      
      
      
    public class ToleranceDataObject : INotifyPropertyChanged
    {
          
        private double _Minimum = 0;
        public double Minimum
        {
            get
            {
                return _Minimum;
            }
            set
            {
                this._Minimum = value;
                RaisePropertyChanged("Minimum");
            }
        }
          
        private double _Maximum = 100;
        public double Maximum
        {
            get
            {
                return _Maximum;
            }
            set
            {
                this._Maximum = value;
                RaisePropertyChanged("Maximum");
            }
        }
          
        private double _SelectionStart = 33;
        public double SelectionStart
        {
            get
            {
                return _SelectionStart;
            }
            set
            {
                this._SelectionStart = value;
                RaisePropertyChanged("SelectionStart");
            }
        }
          
        private double _SelectionEnd = 66;
        public double SelectionEnd
        {
            get
            {
                return _SelectionEnd;
            }
            set
            {
                this._SelectionEnd = value;
                RaisePropertyChanged("SelectionEnd");
            }
        }
          
        public event PropertyChangedEventHandler PropertyChanged; 
        public void RaisePropertyChanged(string propertyName) 
        
            PropertyChangedEventHandler pChanged = PropertyChanged; 
            if (pChanged != null
            
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
            
        
  
          
    }
      
}


1 Answer, 1 is accepted

Sort by
0
Accepted
Kiril Stanoev
Telerik team
answered on 26 Nov 2010, 02:53 PM
Hi Rob,

Just set BindingMode=TwoWay to the Minimum and Maximum bindings.

<Grid Background="YellowGreen" Margin="5">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="30" />
        <ColumnDefinition Width="1*" />
        <ColumnDefinition Width="30" />
    </Grid.ColumnDefinitions>
    <telerik:RadSlider x:Name="sldr2" Grid.Row="0" Grid.Column="1"
            IsSelectionRangeEnabled="True" Minimum="{Binding Minimum, Mode=TwoWay}"
            Maximum="{Binding Maximum, Mode=TwoWay}"
            SelectionStart="{Binding SelectionStart, Mode=TwoWay}"
            SelectionEnd="{Binding SelectionEnd, Mode=TwoWay}" />
    <TextBlock Grid.Row="0" Grid.Column="0"
            Text="{Binding SelectionStart, ElementName=sldr2, StringFormat='\{0:n0\}'}"
            HorizontalAlignment="Center" />
    <TextBlock Grid.Row="0" Grid.Column="2"
            Text="{Binding SelectionEnd, ElementName=sldr2, StringFormat='\{0:n0\}'}"
            HorizontalAlignment="Center" />
</Grid>

The output should be the same in all of the sliders. Let me know if this helps.

Greetings,
Kiril Stanoev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
Slider
Asked by
Rob
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Share this question
or