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

Update DataContext from DatePicker whitout leaving input field

7 Answers 80 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Softec
Top achievements
Rank 1
Softec asked on 22 Apr 2009, 11:34 AM
Hi

When entering a date by hand and NOT tabbing/clicking somewhere outside of the RadDatePicker the SelectedDate is not written down to de DataContext. I know this is a usual behavior in WPF and I have a workaround for the TextBox in form of checking the focused element, getting the bindingexpression and updating it before saving my object. 
But this doesn't work for the picker as the focused item is a TextBox and not the picker itself and therefore the bindingexpression doesn't exists on this control. How can I achieve the same result?

My code so far:
   BindingExpression BindingExpr = null
            if (Keyboard.FocusedElement is TextBox) 
            { 
                BindingExpr = (Keyboard.FocusedElement as TextBox).GetBindingExpression(TextBox.TextProperty); 
 
                if (BindingExpr != null
                { 
                    BindingExpr.UpdateSource(); 
                } 
            } 

Thanks for response/advice!

7 Answers, 1 is accepted

Sort by
0
Boyan
Telerik team
answered on 28 Apr 2009, 03:43 PM
Hi Studach,

Unfortunately, this cannot be accomplished at the moment. RadDatePicker does not support this functionality as the properties that can be used are private. There is no way to update the Datepicker and thus DataContext by using the Textbox. 

Sincerely yours,
Boyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Rachel
Top achievements
Rank 2
answered on 12 Aug 2010, 02:20 AM
I am having this same problem, and it is a big issue for my application.

Please tell me there is a way to manually update the DatePicker without losing focus?

Thanks,
Rachel
0
Kaloyan
Telerik team
answered on 17 Aug 2010, 08:42 AM
Hi Rachel,

I am recommending you to use the SelectedValue property instead SelectedDate. This was one of the major changes since the Q2 2010 release as we shipped the new RadDateTimePicker control. As about the problem you are facing - the value entered in the TexBox is being parsed after the control looses its focus. That is why it is not updating the DataContext when on property changed.

Sincerely yours,
Kaloyan
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
Christoph
Top achievements
Rank 1
answered on 17 May 2011, 02:14 PM
Hello,

Have you done any modifications since?

I would like to now if there is a function to force the parsing of the date so that SelectedValue gets updated, even if the field didn't lose the focus.

Thank You
0
Yana
Telerik team
answered on 20 May 2011, 12:01 PM
Hi Christoph,

I suggest you check ParseDateTimeValue event of RadDateTimePicker -  it is fired when you type a character in the control's input box and allows to implement custom parsing of the date.
More information about the event can be found here.

Best regards,
Yana
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
Christoph
Top achievements
Rank 1
answered on 23 May 2011, 08:05 AM
Hello Yana,

Thank you for your reply.

I do not want to implement my own parsing method.
I would just like to tell the datePicker, please parse the text, like DatePicker.ParseDate()

Currently this is only done automatically when the control loses its focus or when the user hits the enter key.
0
Yana
Telerik team
answered on 25 May 2011, 09:54 AM
Hi Christoph,

This is not supported by RadDatePicker - you cannot force parsing the text. In my previous post I suggested to use ParseDateTimeValue event, because in its handler you can get the characters right after they're entered in the input.

Regards,
Yana
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
Tags
DatePicker
Asked by
Softec
Top achievements
Rank 1
Answers by
Boyan
Telerik team
Rachel
Top achievements
Rank 2
Kaloyan
Telerik team
Christoph
Top achievements
Rank 1
Yana
Telerik team
Share this question
or