CrontabBuilder is a simple WPF control that allows users to visually edit a CRONTAB string in the Qaurtz format.
- Fixed a bug in the regular expression that failed to recognize some "every X seconds" crontab strings
See the full changelog
The package is available on NuGet:
To use the control, first add the following namespace to your XAML:
xmlns:ctb="clr-namespace:MasterT.WPF.CrontabBuilder;assembly=MasterT.WPF.CrontabBuilder"
then, just add the control:
<Grid>
<ctb:CrontabEditorControl></ctb:CrontabEditorControl>
</Grid>
The user will be able to select a schduling thanks to a series of dedicated visual controls.
If you want, you can assign a value to the CrontabString
dependency property of CrontabEditorControl
in code (or via XAML) to update the current scheduling configuration. The control will update accordingly. However, note that this will only work for strings in the formats supported by the CrontabEditorControl
. Equivalent strings but with a different format will instead activate the "Custom Crontab string" mode.
You have three ways to obtain the CRONTAB expression for the currently selected scheduling:
Simply read the CrontabString
property of CrontabEditorControl
. This will always hold the updated CRONTAB string, or null if the user has selected some invalid settings
You can also bind to the CrontabString
property (it's a dependency property), so another option is to use data binding, like this:
<Grid>
<ctb:CrontabEditorControl CrontabString="{Binding MyCrontabProperty}"></ctb:CrontabEditorControl>
</Grid>
Lastly, the CrontabEditorControl
exposes a CrontabStringChanged
event, so you can subscribe to it to receive an update every time the user changes the scheduling. Example:
crontabEditorControl.CrontabStringChanged += (s, crontabString) => {
Console.WriteLine("New crontab string: " + crontabString);
};
The CrontabEditorControl
exposes the following dependency properties that can be used for further customization:
ShowCurrentCrontab
- shows or hides the bottom panel that shows the currently selected Crontab stringShowCurrentCrontabDescription
- shows or hides the bottom panel that shows a human-readable description the currently selected Crontab stringShowInfoOutsideMainScroller
- if set totrue
, this will move the description panels outside the mainScrollViewer
that contains all the crontab editing controls. This means the description panel will always be visible even if the editing controls are partially hidden due to lack of vertical space.ShowSecondsMode
- shows or hides the "every X seconds" panelShowMinutesMode
- shows or hides the "every X minutes" panelShowHoursMode
- shows or hides the "every X hours" panelShowDayMode
- shows or hides the "every day" panelShowWeekMode
- shows or hides the "every week" panelShowNthDayOfWeekMode
- shows or hides the "every nth week day" panelShowMonthMode
- shows or hides the "every month" panelShowLastDayOfMonthMode
- shows or hides the "last day of the month" panelShowCustomExpressionMode
- shows or hides the "custom Cron expression" panel
NuGet package can be built by using the dotnet
command line:
dotnet pack MasterT.WPF.CrontabBuilder.csproj -c Release
This project uses Cron Expression Descriptor by Brady Holt
Thanks to Christoffer Pedersen for: localization support, danish translation
Thanks to joaquinsosamartin for: implementation of "every X seconds" mode