0

I have 2 controls: A DatePicker (for the date) and a TextBox (for the time).

Both are linked to the same property MyDate. On startup the date is now and the time is now, but when I update the date the time changes to 0:00. Is there a way to only change the date on the property and leave the time alone?

I understand why and how it is happening but how would I solve this by not altering the property?

 <DatePicker VerticalContentAlignment="Center" FontSize="12" Text="{Binding Path=MyDate, StringFormat='d', UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
 </DatePicker>

<dxe:DateEdit Height="25" MaskUseAsDisplayFormat="True" AllowDefaultButton="False" EditValue="{Binding Path=MyDate}" Mask="HH:mm">
    <dxe:DateEdit.StyleSettings>
         <dxe:DateEditPickerStyleSettings/>
    </dxe:DateEdit.StyleSettings>
</dxe:DateEdit>
Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
user1702369
  • 1,089
  • 2
  • 13
  • 31
  • You should delete this as it is a duplicate of your other post that got an answer. – Nkosi Jan 31 '17 at 12:36
  • Possible duplicate of [Binding Date Only and Time Only](http://stackoverflow.com/questions/41955922/binding-date-only-and-time-only) – Nkosi Jan 31 '17 at 12:47

1 Answers1

3

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.

You should bind the DatePicker and the TextBox to two different source properties, a DateTime? and a TimeSpan 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

mm8
  • 163,881
  • 10
  • 57
  • 88