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

Silverlight 5 DatePicker binding behavior issue

10 Answers 131 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 21 Feb 2012, 09:29 PM
This code worked in SIlverlight 4. The only thing I did was upgrade to the S5 telerik controls, and now the control is failing.

Here is the xaml:

<telerik:RadDatePicker SelectedDate="{Binding WeekEndingDate, Mode=TwoWay}" Grid.Row="0" Grid.Column="1" Width="100" HorizontalAlignment="Left" DisplayFormat="Short" InputMode="DatePicker"/>

Here is the viewmodel property setter code.
public DateTime? WeekEndingDate
{
get
{
return this.weekEndingDate;
}
set
{
if (value != null)
{
if (this.weekEndingDate != value)
{
DateTime newDate = (DateTime)value;
DateTime selectedWeekEnding = newDate.AddDays(DayOfWeek.Saturday - newDate.DayOfWeek);
this.weekEndingDate = selectedWeekEnding;
this.WeeklyInput = this.weeklyInputs.Where(wi => wi.WeekEntry == selectedWeekEnding).FirstOrDefault();
this.OnPropertyChanged("WeekEndingDate");
}
}
}
}


What I am doing is, whichever date the user selects on the calendar, it adjusts the date to the Saturday of the selected week. Again, this code worked in S4 version. With the upgrade, the property value is changing, the WeeklyInput entity with the right saturday date is found, but the Date text on the control is not changing to the new value of the property.

Is there a way I can do this with the new version that is better than what I have implemented?
Thank you,

- Thomas.

10 Answers, 1 is accepted

Sort by
0
Ivo
Telerik team
answered on 24 Feb 2012, 04:39 PM
Hello,

What version did you previously used? I tested this with 2011 Q2 SL4, 2011 Q3 SL4 and 2012 Q1 SL4 and it behaved the same way with all of these. We believe this is expected Silverlight behavior. When the UI changes the ViewModel it is smart enough not to get notified, about this change. You can test it with a sample TextBox control and it will behave the same way.

Greetings,
Ivo
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Thomas
Top achievements
Rank 1
answered on 24 Feb 2012, 08:17 PM
I left out the details about the notification implementation, believing the "OnPropertyChanged" implementation is standard and would be understood. The ViewModel implements the INotifyPropertyChanged interface, and OnPropertyChanged is the implementation that tells the control to refresh its DependencyProperty via a PropertyChangedEventHandler. But the control is not updating since I upgraded the controls to S5.

However, I've discovered the same problem with the sdk version of the DatePicker, so this clearly isn't a RadDatePicker issue. Interestingly, if I put two RadDatePickers on the page and bind them to the same property, the one I am not selecting from does get updated via the Notification. So it has something to do with the one picker being in an editing state or something. Maybe it's a Silverlight 5 issue. I will investigate since the problem isn't limited to the Telerik control. Thanks.
0
Ivo
Telerik team
answered on 27 Feb 2012, 10:15 AM
Hello,

The problem actually is that you are updating the source for the Binding while the Binding is updating your property. As I said the dependency property is clever enough not to get updated when it is updating your property. You can find a sample project demonstrating the same behavior in Silverlight 4 with two TextBoxes. This could be workarounded by calling the OnPropertyChanged into a dispatcher.

Greetings,
Ivo
the Telerik team
0
Ben
Top achievements
Rank 1
answered on 26 Jun 2012, 11:14 AM
Have you found a solution? I just recognized this strange behavior that you've reported and I am 100% sure that a few months ago everything was ok.
0
Ivo
Telerik team
answered on 27 Jun 2012, 07:17 AM
Hi Ben,

This sounds really strange. I have just tested it with Q2 2011, Q3 2011, Q1 2012 and Q2 2012 and the behavior was absolutely the same with all of them. As I mentioned before this is the expected behavior and it can be easily reproduced with a simple TextBox too.

Kind regards,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Rob Ainscough
Top achievements
Rank 1
answered on 04 Sep 2012, 08:36 PM
I'm having this problem also with SL5 ... both the SDK:DatePicker and the telerik:RadDatePicker ... they will not display my binding.  I've tried converters and still nothing works??  I have no problem binding same viewmodel to a textbox, so what gives here?

<telerik:RadDatePicker x:Name="DateDatePicker" Grid.Column="1" Grid.Row="4" SelectedDate="{Binding Path=TodoList.ToDoSystemDate, Mode=TwoWay}" Margin="2"/>


I'm running v.2012.2.725.1050 and I'm implementing INotifyPropertyChanged.

The underlying viewmodel property is of type Date (VB.NET).

Rob.

0
Rob Ainscough
Top achievements
Rank 1
answered on 04 Sep 2012, 08:54 PM
Discovered the problem ... if the value from the ViewModel is of type "Date" and contains "any" time element as part of the Date, you MUST set the InputMode="DateTimePicker".   In further testing, it appears that DatePicker will not work (Binding) with any "Date" types (VB) at all when the InputMode="DatePicker".

Now this doesn't make much sense to me because the DisplayFormat = "Short", so why would the telerik:RadDatePicker just toss away the binding value??  What's even worse is that it doesn't trigger any binding errors so I can't use that to help me debug why this didn't work.  Is this a known bug because it would be a TALL stretch to suggest this is "by design" ;)

Rob

0
Ivo
Telerik team
answered on 05 Sep 2012, 08:20 AM
Hi Rob,

I am not sure I completely understand the issue you experience. It would be great if you open a new support ticket and attach a sample project there.

Regards,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Rob Ainscough
Top achievements
Rank 1
answered on 06 Sep 2012, 04:41 AM
The issue is simple:
If a date value includes time (i.e. Dim myDate as Date = #1/1/2012 12:15:00 AM#) and the RadDatePicker.InputMode = "DatePicker" the binding will fail (note it will NOT generate any Binding error).

The solution is simple:
The RadDatePicker.InputMode MUST always be set to "DateTimePicker" in order for Binding to work.

Don't really have time to attach projects and can't provide existing real world projects due to confidentiality.  But I didn't expect RadDatePicker to simply reject the binding especially when the DisplayFormat="Short" ... in other words RadDatePicker is much more rigid with Binding input than it should be ... especially considering the existance of a DisplayFormat property.  I would have expected the RadDatePicker to have accepted the binding data even when InputMode="DatePicker" and simply NOT display the time portion per the DisplayFormat="Short" setting ... what I didn't expect was it to display nothing/blank and not trigger any error at all.  This makes my debugging EXTREMELY difficult.

I'm not really picking on Telerik as this appears to be a common problem with Silverlight in general ... one never really knows what restrictions happen with Binding, sometimes it's flexible, sometimes it's not.  It's a case of "trial and error" because once again, a serious lack of documentation and good usage examples.  Again, not picking on Telerik because Microsoft are just as bad with their documentation.  It almost feels like it's intentional, so that someone can write a book and make some money ;)  But sadly, I've read most of the books and none of them really get into details like this.

Rob
0
Ivo
Telerik team
answered on 11 Sep 2012, 08:04 AM
Hello Rob,

I believe that the behavior you describe is related to the RadDatePicker parsing logic and not a binding issue. The RadDatePicker with InputMode="DatePicker" will not expect a time portion into the input value and the control will not successfully parse it. If you write custom parsing logic this will work the way you expect. Another simpler solution that you already mentioned is to set the InputMode to DateTimePicker.

All the best,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
DatePicker
Asked by
Thomas
Top achievements
Rank 1
Answers by
Ivo
Telerik team
Thomas
Top achievements
Rank 1
Ben
Top achievements
Rank 1
Rob Ainscough
Top achievements
Rank 1
Share this question
or