Back to Devexpress

DxScheduler.AppointmentFormShowing Event

blazor-devexpress-dot-blazor-dot-dxscheduler-41770c2d.md

latest10.5 KB
Original Source

DxScheduler.AppointmentFormShowing Event

Fires before the appointment form is shown.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
[Parameter]
public EventCallback<SchedulerAppointmentFormEventArgs> AppointmentFormShowing { get; set; }

Event Data

The AppointmentFormShowing event's data class is SchedulerAppointmentFormEventArgs. The following properties provide information specific to this event:

PropertyDescription
AppointmentSpecifies the target appointment. Inherited from SchedulerAppointmentOperationEventArgs.
CancelGets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
FormInfoSpecifies the appointment form information.
FormTypeSpecifies the appointment form type.
TitleSpecifies the appointment form’s title.

Remarks

This event is raised before the extended or compact appointment form is shown. Use the event argument’s FormType property to identify which form is used. Use the SchedulerAppointmentOperationEventArgs.Appointment property to access the appointment for which the form is displayed. The FormInfo property stores form settings.

Suppress the Appointment Form

If you want to suppress the Appointment form, set the event argument’s Cancel property to true.

razor
<DxScheduler StartDate="@DateTime.Today"
             DataStorage="@DataStorage"
             ActiveViewType="SchedulerViewType.WorkWeek"
             AppointmentFormShowing="OnAppointmentFormShowing">
    @*...*@
</DxScheduler>

@code {
    void OnAppointmentFormShowing(SchedulerAppointmentFormEventArgs args) {
        if (args.FormType == SchedulerAppointmentFormType.CompactEditForm) { 
            args.Cancel = true;
        }
    }
    // ...
}

Add Custom Fields to Appointment Forms

If an appointment contains custom properties, you need to pass information about them to the edit form. Implement a SchedulerAppointmentFormInfo descendant and declare the corresponding properties in the class. Then, handle the AppointmentFormShowing event and assign a custom descendant instance to the event argument’s FormInfo property.

For additional information, refer to the following help topic: Custom Appointment Form.

razor
<DxScheduler StartDate="@DateTime.Today"
             DataStorage="@DataStorage"
             ActiveViewType="SchedulerViewType.WorkWeek"
             AppointmentFormShowing="OnAppointmentFormShowing">
    @*...*@
</DxScheduler>

@code {
    public class CustomAppointmentFormInfo : SchedulerAppointmentFormInfo {
        public CustomAppointmentFormInfo(DxSchedulerAppointmentItem AppointmentItem, DxSchedulerDataStorage DataStorage)
            : base(AppointmentItem, DataStorage) { }

        public bool IsAccepted {
            get { return (bool)CustomFields["IsAccepted"]; }
            set { CustomFields["IsAccepted"] = value; }
        }
    }

    void OnAppointmentFormShowing(SchedulerAppointmentFormEventArgs args) {
        args.FormInfo = new CustomAppointmentFormInfo(args.Appointment, DataStorage);
    }
}
csharp
public class Appointment {
    public Appointment() {}
    public int AppointmentType { get; set; }
    public DateTime StartDate { get; set; }
    // ...
    public bool Accepted { get; set; }
}
csharp
public static partial class AppointmentCollection {
    public static List<Appointment> GetAppointments() {
        DateTime date = DateTime.Today;
        var dataSource = new List<Appointment>() {
                new Appointment {
                    Caption = "Install New Router in Dev Room",
                    StartDate = date + (new TimeSpan(0, 10, 0, 0)),
                    EndDate = date + (new TimeSpan(0, 12, 30, 0)),
                    Label = 6,
                    Status = 4
                },
                // ...
            };
        return dataSource;
    }
}

Customize Forms for Recurring Appointments

When a user creates a recurring appointment and selects a value other than Never in the Appointment form’s Repeat section, the Recurrence form appears.

You can change the list of items available in the Appointment form’s Repeat section. To do this, handle the AppointmentFormShowing event and use the SchedulerAppointmentFormInfo.RepeatItems property to define the item list.

In the Recurrence form, you can change the list of repeat end items and the list of week days available for Repeat Monthly and Repeat Yearly appointments. To do this, handle the Scheduler’s AppointmentFormShowing event, use the RecurrenceFormInfo property to get information about the Recurrence form, modify RepeatEndItems and WeekDayItems properties.

The following code snippet does the following:

  • Defines three items in the Appointment form’s Repeat list: Yearly, Weekly, Never. The list displays items in the same order as in code.

  • Customizes the Recurrence form:

  • Index.razor

  • Appointment

  • AppointmentCollection

razor
<DxScheduler DataStorage="@DataStorage" 
             AppointmentFormMode="SchedulerAppointmentFormMode.EditForm"
             AppointmentFormShowing="OnAppointmentFormShowing">
    <DxSchedulerWeekView ShowWorkTimeOnly="true" />
</DxScheduler>

@code {
    DxSchedulerDataStorage DataStorage = new DxSchedulerDataStorage() {
            AppointmentsSource = AppointmentCollection.GetAppointments(),
            AppointmentMappings = new DxSchedulerAppointmentMappings() {
                Start = "StartDate",
                End = "EndDate",
                Subject = "Caption",
                LabelId = "Label",
                StatusId = "Status"
            }
        };

    void OnAppointmentFormShowing(SchedulerAppointmentFormEventArgs args) {
        args.FormInfo.RepeatItems = new List<SchedulerRecurrenceType>() {
            SchedulerRecurrenceType.Yearly,
            SchedulerRecurrenceType.Weekly,
            SchedulerRecurrenceType.Never
        };

        args.FormInfo.RecurrenceFormInfo.RepeatEndItems = new List<SchedulerRecurrenceRange>() {
            SchedulerRecurrenceRange.OccurrenceCount,
            SchedulerRecurrenceRange.EndByDate
        };

        args.FormInfo.RecurrenceFormInfo.WeekDayItems.Remove(SchedulerWeekDays.WeekendDays);
    }
}
csharp
public class Appointment {
    public Appointment() {}
    public int AppointmentType { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public string Caption { get; set; }
    public string Description { get; set; }
    public string Location { get; set; }
    public int Label { get; set; }
    public int Status { get; set; }
    public bool AllDay { get; set; }
    public string Recurrence { get; set; }
    public bool Accepted { get; set; }
}
csharp
public static partial class AppointmentCollection {
    public static List<Appointment> GetAppointments() {
        DateTime date = DateTime.Today;
        var dataSource = new List<Appointment>() {
                new Appointment {
                    Caption = "Install New Router in Dev Room",
                    StartDate = date + (new TimeSpan(0, 10, 0, 0)),
                    EndDate = date + (new TimeSpan(0, 12, 30, 0)),
                    Label = 6,
                    Status = 4
                },
                new Appointment {
                    Caption = "Upgrade Personal Computers",
                    StartDate = date + (new TimeSpan(0, 13, 0, 0)),
                    EndDate = date + (new TimeSpan(0, 15, 30, 0)),
                    Label = 1,
                    Status = 4
                },
                new Appointment {
                    Caption = "Website Redesign Plan",
                    StartDate = date + (new TimeSpan(1, 9, 30, 0)),
                    EndDate = date + (new TimeSpan(1, 12, 0, 0)),
                    Label = 1,
                    Status = 1,
                    Accepted = true
                },
                new Appointment {
                    Caption = "New Brochures",
                    StartDate = date + (new TimeSpan(1, 13, 30, 0)),
                    EndDate = date + (new TimeSpan(1, 15, 15, 0)),
                    Label = 8,
                    Status = 2,
                    Accepted = true
                },
                // ...
            };
        return dataSource;
    }
}

See Also

DxScheduler Class

DxScheduler Members

DevExpress.Blazor Namespace