How to set DateEditBox.SetValueToNowCommand or change the behavior

Editors for WPF Forum

Posted 5 months ago by Brad Salmon
Version: 19.1.0684
Avatar

In our test environment, we have our own concept of "today". I see the DateEditBox has SetValueToNowCommand and SetValueToTodayCommand properties, but both are read-only. I don't understand the point of having those properties if they are read-only. How can I change the logic that gets executed when setting to "Now" or "Today"?

[Modified 5 months ago]

Comments (3)

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

Hi Brad,

They are just simple built-in helper commands that can optionally be bound to external UI buttons.  I don't believe we use them anywhere by default.

If trying to unit test with them, your options would be to:

1) Make your own command that sets the edit box's Value property based on a supplied DateTime command parameter.  This is the Today one's logic:

this.Value = DateTimeHelper.Range(DateTime.Today, this.Minimum, this.Maximum);

2) Or alternatively change your unit test logic so it checks to see if the value after executing the command is within a second of the current DateTime (for SetValueToNowCommand), or within a day of the current date (for SetValueToTodayCommand).  That way edge cases like being executed right at midnight, etc. are handled.


Actipro Software Support

Posted 5 months ago by Brad Salmon
Avatar

I should have been more specific in my question (although the answer may still be the same). When I have a DateEditBox and HasPopup=true, when I click on it to make the popup appear, down at the bottom is a button that say "Today " and then today's date. So ultimately I would like to have control over what is shown there as "Today's" date.

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

Hi Brad,

The Today button in the MonthCalendar nested in the DateEditBox template's popup is coming from the read-only MonthCalendar.SelectTodayCommand property.  It's effectively setting DateTime.Today to the MonthCalendar.SelectedDate as long as that date is within the allowed range.  There isn't really a way to customize that, so if you are unit testing, you'd have to look for DateTime.Today or within a day of that if you want to handle the extremely rare scenario that your unit test executes exactly over the course of transitioning to midnight.


Actipro Software Support

The latest build of this product (v2019.1 build 0685) was released 4 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.