0

I have a datePicker, whose Text property I have bound to a view model.

Instead of chosing UpdateSourceTrigger as propertyChanged, I am using Explicit. In the KeyDown event I calling the binding.UpdateSource() method.

The problem i am facing is, when I enter a value 30/10/1983 in the textbox, in the view model, I end up having only the value 30/10/198. I do not get the last entered number, unless I do a lostfocus or tabout.

The moment I enter the first value 3, the view model property gets notified as NULL.

Should I subscribe to some other event?

Is there something wrong which I am doing, can someone help.

Also, I am using string property in the viewmodel instead of DateTime? is this correct approach or not?

Thanks

4
  • What are you doing in the KeyDown event that requires you to update the source explicitly? The issue at hand is that the KeyDown event is called before the DatePicker value is updated, but I can't find any events that are raised after. Commented Nov 10, 2014 at 9:20
  • @hantoun i too am not finding any such event. I need the datepicker to accept user input in the form of dd/mm/yyyy. this entry does not trigger a postback to the view model. but entering the date in the format mm/dd/yyyy does trigger a post back. Commented Nov 10, 2014 at 9:52
  • Perhaps this question could help you find the solution you were looking for. I would attempt to set the correct CultureInfo instead of messing with static formats, if I were you. In any case, it'll allow you to bind to DateTime sources. Commented Nov 10, 2014 at 10:06
  • @hantoun I tried changing the string format, but its not working for me,it still accepts mm/dd/yyyy and not dd/mm/yyyy Commented Nov 10, 2014 at 11:03

1 Answer 1

0

Call binding.UpdateSource() inside Dispatcher to make this work. My assumption is datePicker updating the value only after TextChanged event. So moving binding.UpdateSource() inside a Dispatcher call will resolve your problem. http://msdn.microsoft.com/en-us/library/cc190824%28v=vs.110%29.aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.