End-User Restrictions
- 4 minutes to read
The SchedulerControl allows you to prohibit the user to create or edit (delete, drag, etc.) appointments shown within the scheduling area. With the restriction applied, all corresponding UI elements, such as ribbon and popup menu items, are disabled.
Use AllowAppointments… properties to prohibit a specific action for all appointments. Handle the corresponding CustomAllow… event to define custom logic to allow the user to perform an action.
Note
The SchedulerControl uses the CommandManager class to manage commands the ribbon or context menu items execute. The RequerySuggested event is fired when any changes that can affect the command’s ability to execute (for example, changing focus) are made. It notifies the command that it should raise the CanExecuteChanged event, which makes some CustomAllow… events fire as well. This chain of events can occur involuntarily, so make sure that the event handler does not contain any code that may affect the application’s performance.
All the available properties and their corresponding events are listed below. These are all dependency properties.
The code sample below shows how to handle the SchedulerControl.CustomAllowAppointmentCreate event to restrict creating appointments for a specific time interval, and SchedulerControl.CustomAllowAppointmentConflicts event to prohibit dragging appointments to this time interval as well:
private void schedulerControl1_CustomAllowAppointmentCreate(object sender, AppointmentItemOperationEventArgs e)
{
//Retrieve the selected interval:
DateTimeRange selectedIntervalRange = schedulerControl1.SelectedInterval;
TimeInterval selectedInterval = new TimeInterval(selectedIntervalRange.Start, selectedIntervalRange.End);
//Check whether the selected interval intersects with the resticted interval:
//If true, restrict appointment creation
e.Allow = IsIntervalAllowed(selectedInterval);
}
private void schedulerControl1_CustomAllowAppointmentConflicts(object sender, AppointmentItemConflictEventArgs e)
{
//Obtain the selected interval:
TimeInterval interval = e.Interval;
//If the appointment is to be moved to the restricted time interval,
//Add the dragged appointment the conflicting appointments collection:
if (!IsIntervalAllowed(interval))
e.Conflicts.Add(e.AppointmentClone);
}
//This method is used to check
//whether the target interval intersects with the resticted interval:
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;
}