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

How To Make ScheduleView ReadOnly

Environment

Product Version 2019.1.220
Product RadScheduleView for WPF

Description

How to show a readonly schedule in RadScheduleView.

Solution

Create a class inheriting ReadOnlyBehavior and set an instance of it to the ReadOnlyBehavior property of the RadScheduleView. Override the virtual methods in order to disable deleting, dragging, editing, resizing, saving an appoitment and editing a slot by simply returning false in all of them.

  1. Define the ViewModel

        public class ViewModel : ViewModelBase 
        { 
            public ObservableCollection<Appointment> Appointments { get; private set; } 
     
            public ViewModel() 
            { 
                var today = DateTime.Today; 
                var endOfDay = new DateTime(today.Year, today.Month, today.Day, 23, 59, 59); 
                var startOfDay = new DateTime(today.Year, today.Month, today.Day, 0, 0, 0); 
     
                this.Appointments = new ObservableCollection<Appointment>() 
                { 
                    new Appointment() { Subject = "First Appointment", Start = startOfDay, End = startOfDay.AddHours(1)}, 
                    new Appointment() { Subject = "Last Appointment", Start = endOfDay.AddHours(-1), End = endOfDay} 
                }; 
            } 
        } 
    
  2. Create the custom ReadOnlyBehavior

        public class CustomReadOnlyBehavior : ReadOnlyBehavior 
        { 
            public override bool CanSaveAppointment(IReadOnlySettings readOnlySettings, IOccurrence occurrence) 
            { 
                return false; 
            } 
     
            public override bool CanEditAppointment(IReadOnlySettings readOnlySettings, IOccurrence occurrence) 
            { 
                return false; 
            } 
     
            public override bool CanDragAppointment(IReadOnlySettings readOnlySettings, IOccurrence occurrence) 
            { 
                return false; 
            } 
     
            public override bool CanResizeAppointment(IReadOnlySettings readOnlySettings, IOccurrence occurrence) 
            { 
                return false; 
            } 
     
            public override bool CanDeleteAppointment(IReadOnlySettings readOnlySettings, IOccurrence occurrence) 
            { 
                return false; 
            } 
     
            public override bool CanEditSlot(IReadOnlySettings readOnlySettings, Slot slot) 
            { 
                return false; 
            } 
        } 
    
  3. Define a RadScheduleView and set its ReadOnlyBehavior property.

        <Grid> 
            <Grid.DataContext> 
                <local:ViewModel /> 
            </Grid.DataContext> 
     
            <telerik:RadScheduleView AppointmentsSource="{Binding Appointments}"> 
                <telerik:RadScheduleView.ViewDefinitions> 
                    <telerik:DayViewDefinition /> 
                </telerik:RadScheduleView.ViewDefinitions> 
                <telerik:RadScheduleView.ReadOnlyBehavior> 
                    <local:CustomReadOnlyBehavior /> 
                </telerik:RadScheduleView.ReadOnlyBehavior> 
            </telerik:RadScheduleView> 
        </Grid> 
    

    Note that the namespace "local" refers to the namespace where the CustomReadOnlyBehavior class is defined.

See Also

In this article