New to Telerik UI for WinUI? Download free 30-day trial

AppointmentSelectionBehavior

In RadScheduler there are plugin selection behaviors that make it possible to customize the logic behind all selections in the control. There are selection behaviors like AppointmentSelectionBehavior, SlotSelectionBehavior etc.

AppointmentSelectionBehavior is responsible for executing the selection logic of appointments in the control. Its default behavior is for single, multiple and extended selection. It is possible to customize the behavior in order to restrict selecting appointments in different resources, selecting more than one appointment etc.

Disable multiple appointments selection based on ResourceName

This tutorial will go through on how to create a custom AppointmentSelectionBehavior in the scenario when there are different resources in the Scheduler control and it is required to disable simultaneous selection of appointments in different resource groups.

Before proceeding with this tutorial first read about Resources in RadScheduler.

  • Create CustomAppointmentSelectionBehavior class that inherits AppointmentSelectionBehavior class:

Example 1

public class CustomAppointmentSelectionBehavior : AppointmentSelectionBehavior 
{ 
} 
  • Override the GetSelectedAppointments method:

Example 2

public class CustomAppointmentSelectionBehavior : AppointmentSelectionBehavior 
{ 
    protected override IEnumerable<IOccurrence> GetSelectedAppointments(AppointmentSelectionState state, IOccurrence target) 
    { 
        var result = base.GetSelectedAppointments(state, target); 
 
        if (result.Skip(1).Any()) 
        { 
            var firstSelected = state.CurrentSelectedAppointments.First(); 
            var firstSelectedAppointment = GetAppointment(firstSelected); 
            var firstSelectedResource = firstSelectedAppointment.Resources[0]; 
 
            return result.Where(occ => GetAppointment(occ).Resources.Contains(firstSelectedResource)); 
        } 
        return result; 
    } 
 
    private static IAppointment GetAppointment(IOccurrence occurence) 
    { 
        return occurence is IAppointment ? ((IAppointment)occurence) : ((Occurrence)occurence).Appointment; 
    } 
} 
  • All that is left is to attach the newly created custom behavior to the Scheduler:

Example 3

<telerik:RadScheduler ...> 
    ... 
    <telerik:RadScheduler.AppointmentSelectionBehavior> 
        <local:CustomAppointmentSelectionBehavior/> 
    </telerik:RadScheduler.AppointmentSelectionBehavior> 
    ... 
</telerik:RadScheduler> 
Finally the Scheduler control in the XAML should look like this:

Example 4

<telerik:RadScheduler ...> 
    ... 
    <telerik:RadScheduler.ResourceTypesSource> 
        <telerik:ResourceTypeCollection> 
            <telerik:ResourceType Name="Location"> 
                <telerik:Resource ResourceName="Room 1" /> 
                <telerik:Resource ResourceName="Room 2" /> 
                <telerik:Resource ResourceName="Room 3" /> 
            </telerik:ResourceType> 
        </telerik:ResourceTypeCollection> 
    </telerik:RadScheduler.ResourceTypesSource> 
    <telerik:RadScheduler.GroupDescriptionsSource> 
        <telerik:GroupDescriptionCollection> 
            <telerik:ResourceGroupDescription ResourceType="Location" /> 
        </telerik:GroupDescriptionCollection> 
    </telerik:RadScheduler.GroupDescriptionsSource> 
    <telerik:RadScheduler.AppointmentSelectionBehavior> 
        <local:CustomAppointmentSelectionBehavior /> 
    </telerik:RadScheduler.AppointmentSelectionBehavior> 
    ... 
</telerik:RadScheduler> 

See Also

In this article
Not finding the help you need?