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: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)); } } } }
