I have 2 controls:
DatePicker: For Date Only
TextBox with TimeMask: For Time Only
They are both linked to the same property DateTime EffectiveDate
But the problem is when I change the Date on the DatePicker, it changes the Time in the TimeTextBox back to 12:00.
I understand the reason for it, but what best solution is out there to let these work separately but bound to the same property?
I have tried to take the current time and build a new Date in the set property but always end up with overflow errors.
You can use a value converter to hold on to the value
And have the two controls in question bind to the one property but have the date picker use the converter to not override the time.
Catch
dateTimePicker1_ValueChanged
event and then setbinded field value
combiningdate
andtime
partsYou could do something like this:
The built-in DatePicker control selects only a date without any specific time so I am afraid it makes no sense to try to display the time of the selected date in a TextBox. The DatePicker will effectively clear out the time part each time a new date is selected. This is how the control works.
So you should bind the DatePicker and the TextBox to two different source properties, a
DateTime?
and aTimeSpan
respectively.The other option would be to use another control that selects a date and a time, for example this one: http://wpftoolkit.codeplex.com/wikipage?title=DateTimePicker