This example applies the following user restrictions:
- Prevents users from creating new appointments.
- Prevents users from moving appointments to the lunch break interval (12:00–13:00).
In this example, the Ribbon UI displays Disable Creating Appointments and Disable Appointment Conflict controls that toggle these restrictions.
In this example, the restricted interval covers the lunch break time (12:00–13:00):
TimeInterval lunchTime = new TimeInterval(DateTime.Today.AddHours(12), TimeSpan.FromHours(1));
The IsIntervalAllowed
method returns false
if any part of the selected interval overlaps with the restricted time range:
private bool IsIntervalAllowed(TimeInterval interval) {
DateTime dayStart = interval.Start.Date;
while (dayStart < interval.End) {
if (interval.IntersectsWithExcludingBounds(lunchTime))
return false;
dayStart = dayStart.AddDays(1);
}
return true;
}
The CustomAllowAppointmentCreate
event allows you to define rules that restrict appointment creation. In this example, the event handler:
- Blocks appointment creation if Disable Creating Appointments is turned on.
- Prevents users from creating appointments during lunch time if Disable Creating Appointments is turned off.
private void customAllowAppointmentCreateHandler(object sender, AppointmentItemOperationEventArgs e) {
// Cancel the operation if the "Disable Creating Appointments" bar item is checked
if((bool)barItemDisableCreatingAppointments.IsChecked) {
e.Allow = false;
return;
}
DateTimeRange selectedIntervalRange = schedulerControl1.SelectedInterval;
TimeInterval selectedInterval = new TimeInterval(selectedIntervalRange.Start, selectedIntervalRange.End);
e.Allow = IsIntervalAllowed(selectedInterval);
}
The barItemDisableCreatingAppointments.IsChecked
flag is bound to the Disable Creating Appointments Ribbon item and acts as a switch.
The CustomAllowAppointmentConflicts event allows you to control how the scheduler handles appointment conflicts. In this example, a conflict occurs when a user moves an appointment to a time interval that already contains another appointment or to the lunch break time. In the Ribbon UI, you can enable the Disable Appointment Conflicts item to ignore conflicts.
private void customAllowAppointmentConflictsHandler(object sender, AppointmentItemConflictEventArgs e) {
if((bool)barItemDisableAppointmentConflicts.IsChecked) {
e.Conflicts.Clear(); // clear all restrictions
return;
}
TimeInterval interval = e.Interval;
if (!IsIntervalAllowed(interval))
e.Conflicts.Add(e.AppointmentClone);
}
The barItemDisableAppointmentConflicts.IsChecked
flag is bound to a custom Ribbon item (Disable Appointment Conflict) that toggles this behavior.
- MainWindow.xaml (VB: MainWindow.xaml)
- MainWindow.xaml.cs (VB: MainWindow.xaml.vb)
- RestrictionsViewModel.cs (VB: RestrictionsViewModel.vb)
- SampleData.cs (VB: SampleData.vb)
- WPF Scheduler - Customize the Built-In Ribbon Control
- WPF Scheduler - Specify Custom Work Time Intervals
- WPF Scheduler - Filter Time Regions
- WPF Scheduler - ICalendar Support
- WPF Scheduler - Apply User Restrictions
(you will be redirected to DevExpress.com to submit your response)