Preserving seconds when using the TimeEditBox

Editors for WPF Forum

Posted 5 months ago by William Leary
Version: 22.1.5
Avatar

We use the TimeEditBox control in our application. It is bound to a DateTime variable where we have the seconds set to 59, which is a specific requirement. In other words, if the TimeEditBox is showing 10:17 AM, we would have initially populated it with a DateTime variable that has a time portion of 10:17:59. And if someone edits it to 2:30 PM, we would want the time portion to be updated to 14:30:59. Since the seconds will always need to be 59, we don't want to explicitly show that to the users, or allow them to set it to some other value. The XAML looks like so:

<actipro:TimeEditBox Value="{Binding Path=ToTime, Mode=TwoWay ,ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
				         Format="t"
                         VerticalAlignment="Center" Width="80" Margin="3" />

Recently a bug was reported and we tracked it down to the seconds being incorrectly set to 0, and not keeping the expected 59 seconds. What we discovered is that if a user manually edits, via typing, the hour/minute/amPm portion of the control, the seconds get set to 0. If a user uses the drop-down hour/minute picker, then the control preserves the seconds! I have searched the documentation to try and find any property to control this behavior but I can't seem to find anything. I'm not understanding why setting the time via the picker vs typing would alter the behavior of how the seconds are preserved. We are using v22.1.5 of the suite.

I know we could add logic in the setting that is being called in our view model to set the seconds to 59 explicitly, but wondered if there was a cleaner/better way to be able to specify this somehow directly in the TimeEditBox definition. Thanks!

Comments (1)

Posted 5 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

The reason that currently happens is that the edited (via typing) text calls DateTime's parse methods and uses the result.  It's not considering which edit box parts are currently displayed and is just accepting the parsed result.

For v24.1, we are going to update our logic to examine which parts are displayed and will only update those related components in the DateTime value when parsing text into a DateTime.  That will allow you to keep the 59 seconds if your TimeEditBox only shows hours and minutes.

For the version you have, as a workaround until v24.1, you can probably override the TimeEditBox.CoerceParsedValue method and ensure that the returned value (if not null) has 59 seconds.


Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.