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

RadDate Picker causes app to crash

3 Answers 73 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Top Gun
Top achievements
Rank 1
Top Gun asked on 22 Jan 2013, 11:03 PM

I am using Silverlight 5. Telerik 2011.1 419.  I have a RadDatePicker with DisplayDateStart="1/1/1985" and DisplayDateEnd="1/1/2100".  When the SelectedDate property  is set to 1/1/2000, the application runs fine.  However, when the SelectedDate property  is set to 1/1/2200, the application crashes. (Note: I cannot attach sample solution.)
 

I am trying to specify a range of accepted values for the date picker calendar.  However,  I cannot guarantee the SelectedDate property will always get a date value in the specified range.  What is the best way to fix this problem and prevent the application from crashing?

Xaml

 

<Grid x:Name="LayoutRoot" Background="White">        
       <telerik:RadDatePicker SelectedDate="{Binding SelectedDate, Mode=TwoWay}" DisplayDateStart="1/1/1985" DisplayDateEnd="1/1/2100" Height="30" Width="150" Margin="50,45,0,0"/>
   </Grid>

C#
public MainPage()
      {
          InitializeComponent();
          DataContext = this;
      }
      private DateTime? _selectdDate = null;
      public DateTime? SelectedDate
      {
          get { return _selectdDate; }
          set
          {
              _selectdDate = value;
              NotifyPropertyChanged("SelectedDate");
          }
      }
      public event PropertyChangedEventHandler PropertyChanged;
      public void NotifyPropertyChanged(string propertyName)
      {
          if (PropertyChanged != null)
          {
              PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
      }
      private void UserControl_Loaded(object sender, RoutedEventArgs e)
      {
          SelectedDate = new DateTime(2000,1,1);
          //This will not work! DateTime(2300,1,1); 
      }

3 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 25 Jan 2013, 02:45 PM
Hello,

We tried to reproduce the issue but to no avail.

Could you share with us more details on the exceptions you are getting and any related details that may be important in your scenario? Some screenshots would be helpful.

Kind regards,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Top Gun
Top achievements
Rank 1
answered on 25 Jan 2013, 09:07 PM
Hi Vladi,

Thank you for replying to my post.  Again I am using Telerik RadControls for Silverlight, version 2011.1 419.  Maybe you tried this on a different version.  I built Telerik's source code for version 2011.1.419.  Look at method OnDisplayDateEndChanged. When a DisplayEndDate is Invalid, the application will throw an exception.  On line 3049, I just commented out throwing the exception.  (See below)

private static void OnDisplayDateEndChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            RadCalendar calendar = sender as RadCalendar;
            DateTime? newDisplayDateEnd = e.NewValue as DateTime?;
  
            if (IsDisplayDateEndValid(calendar, newDisplayDateEnd))
            {
                if (calendar.Flags.IsLoaded)
                {
                    calendar.UpdateCalendarViews();
                }
            }
            else
            {
                //throw new ArgumentOutOfRangeException("sender", "Invalid DisplayDateEnd value.");
            }
        }


I believe this fix will work.
0
Vladi
Telerik team
answered on 29 Jan 2013, 09:53 AM
Hi,

I checked the old 2011.1 version of the source code and the new current version and the row you are referring to us no longer present in the latest version of RadControls and this issue has been resolve. Since we see you are building the dlls for Silverlight 5 but with a very outdated version of the source code it is recommended that you upgrade to the latest version.

Also note that the source code of RadControls is for educational purposes only and not for customizing of the controls.

If you have any other questions feel free to write to us again.

Regards,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
DatePicker
Asked by
Top Gun
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Top Gun
Top achievements
Rank 1
Share this question
or