Articles in this section

How to add additional attributes to appointments WPF Scheduler (Calendar)?

In WPF Scheduleryou can add additional attributes for your appointments. In this section, additional attribute (Appointment ID) is added to an appointment. You can get the tapped appointment details when tapping the cell of SfScheduler using the CellTapped event in WPF.

XAML

Interaction behavior added to SfScheduler to handle the CellTapped handler.

<Window.DataContext>
<local:SchedulerViewModel />
</Window.DataContext>
<Grid>
<syncfusion:SfScheduler 
        x:Name="Schedule" 
        ViewType="Week"
        ItemsSource="{Binding AppointmentCollection}">
    <interactivity:Interaction.Behaviors>
        <local:SchedulerBehavior/>
    </interactivity:Interaction.Behaviors>
</syncfusion:SfScheduler>
</Grid>

C#

You need to create a separate class which inherits from ScheduleAppointment and include required properties in this class for adding additional attribute to appointment.

public class CustomAppointment : ScheduleAppointment, INotifyPropertyChanged
{
    private string appointment_ID;
    public string AppointmentID
    {
        get { return appointment_ID; }
        set
        {
            appointment_ID = value;
            OnPropertyChanged("AppointmentID");
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;
    private void OnPropertyChanged(string propertyName)
    {
        var eventHandler = this.PropertyChanged;
        if (eventHandler != null)
            eventHandler(this, new PropertyChangedEventArgs(propertyName));
    }
}

C#

You can schedule a meeting for a day by setting StartTime, EndTime, AppointmentID, AppointmentBackground, and Subject class. Create appointments of type ObservableCollection <CustomAppointment> and assign those appointment collection to the ItemsSource property.

 

public class SchedulerViewModel
{
    public ObservableCollection<CustomAppointment> AppointmentCollection
    {
        get;
        set;
    }
    CustomAppointment scheduleAppointment;
    public SchedulerViewModel()
    {
        scheduleAppointment = new CustomAppointment();
        scheduleAppointment.Subject = "Meeting";
        scheduleAppointment.AppointmentID = "579";
        scheduleAppointment.AppointmentBackground = Brushes.Green;
        scheduleAppointment.StartTime = DateTime.Now.Date.AddHours(10);
        scheduleAppointment.EndTime = DateTime.Now.Date.AddHours(12);
        AppointmentCollection = new ObservableCollection<CustomAppointment>();
        AppointmentCollection.Add(scheduleAppointment);
    }
}

C#

In CellTapped, you can get the tapped appointment ID details by the property of Appointment of CellTappedEventArgs.

public class SchedulerBehavior : Behavior<SfScheduler>
{
    SfScheduler scheduler;
    protected override void OnAttached()
    {
        base.OnAttached();
        scheduler = this.AssociatedObject;
        this.AssociatedObject.CellTapped += Schedule_CellTapped;
    }
    private void Schedule_CellTapped(object sender, CellTappedEventArgs e)
    {
        var appointment = e.Appointment as CustomAppointment;
        if (appointment != null && appointment.Subject == "Meeting")
            MessageBox.Show(" " + " " + appointment.AppointmentID.ToString(), "Selected Appointment ID ", MessageBoxButton.OK);
    }
    protected override void OnDetaching()
    {
        base.OnDetaching();
        this.AssociatedObject.CellTapped -= Schedule_CellTapped;
        this.scheduler = null;
    }
}

Output

Demo image to get the appointment ID details of Appointment in celltappedeventargs.

View sample in GitHub


Conclusion

Hope you enjoyed learning about how to add additional attributes to appointments WPF Scheduler (Calendar).

You can refer to our WPF Scheduler feature tour page to learn about its other groundbreaking feature representations. You can explore our WPF Scheduler documentation to understand how to present and manipulate data.

For current customers, you can check out our Angular components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our Angular Diagram and other Angular components.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied