The requested page is not available for the requested platform. You are viewing the content for Default platform.

SchedulerView.DataSource Property

Gets or sets the data source for the scheduler.

Namespace: DevExpress.XamarinForms.Scheduler

Assembly: DevExpress.XamarinForms.Scheduler.dll

Declaration

public DataSource DataSource { get; set; }

Property Value

Type Description
DataSource

An object that provides data for the scheduler.

Remarks

The DataSource property allows you to bind a SchedulerView instance to an external data source. Use the DataSource.AppointmentsSource, DataSource.AppointmentLabelsSource and DataSource.AppointmentStatusesSource properties to provide data sources for the scheduler's appointments, labels and statuses.

Important

When you bind the scheduler to a data source, you need to map appointment, label and status properties to data source fields. The names of the database fields are usually fixed, and you cannot change them. Mappings are used to adjust the scheduler data model to the existing data model.
Use the DataSource object's AppointmentMappings, AppointmentLabelMappings and AppointmentStatusMappings properties to define which data source fields should serve as sources of data for properties of the scheduler's appointment, label and status.

SchedulerView can also operate in the unbound mode. If you do not bind a data source to the scheduler, it maintains appointments, labels and statuses internally. To manage scheduler items in code, use the following collections:

Examples

This example shows how to bind a SchedulerView instance to a data source that stores custom appointment (MedicalAppointment) and label (MedicalAppointmentType) objects.

  1. Assign a view model object to the content page's BindingContext property.
  2. Set the SchedulerView.DataSource property to a DataSource object and specify the following properties of this object:

    using System;
    using System.Collections.ObjectModel;
    using Xamarin.Forms;
    
    namespace SchedulerExample.Models {
        public class MedicalAppointment {
            public int Id { get; set; }
            public DateTime StartTime { get; set; }
            public DateTime EndTime { get; set; }
            public string Subject { get; set; }
            public int LabelId { get; set; }
            public string Location { get; set; }
        }
    
        public class MedicalAppointmentType {
            public int Id { get; set; }
            public string Caption { get; set; }
            public Color Color { get; set; }
        }
    
        public class ReceptionDeskData {
            public static DateTime BaseDate = DateTime.Today;
    
            public static string[] AppointmentTypes = { "Hospital", "Office", "Phone Consultation", "Home", "Hospice" };
            public static Color[] AppointmentTypeColors = { Color.FromHex("#9c63ff"), Color.FromHex("#64c064"),
                                                        Color.FromHex("#eead51"), Color.FromHex("#d2504b"),
                                                        Color.FromHex("#4b6bbf") };
    
    
            public static string[] PatientNames = { "Andrew Glover", "Mark Oliver", "Taylor Riley",
                                                    "Addison Davis", "Benjamin Hughes", "Lucas Smith",
                                                    "Robert King", "Laura Callahan", "Miguel Simmons",
                                                    "Isabella Carter", "Andrew Fuller", "Madeleine Russell",
                                                    "Steven Buchanan", "Nancy Davolio", "Michael Suyama",
                                                    "Margaret Peacock", "Janet Leverling", "Ariana Alexander",
                                                    "Brad Farkus", "Bart Arnaz", "Arnie Schwartz", "Billy Zimmer"};
    
            static Random rnd = new Random();
    
            void CreateMedicalAppointments() {
                int appointmentId = 1;
                int patientIndex = 0;
                DateTime start;
                TimeSpan duration;
                ObservableCollection<MedicalAppointment> result = new ObservableCollection<MedicalAppointment>();
                for (int i = -20; i < 20; i++)
                    for (int j = 0; j < 20; j++) {
                        int room = rnd.Next(1, 100);
                        start = BaseDate.AddDays(i).AddHours(rnd.Next(8, 17)).AddMinutes(rnd.Next(0, 40));
                        duration = TimeSpan.FromMinutes(rnd.Next(15, 20));
                        result.Add(CreateMedicAppointment(appointmentId, PatientNames[patientIndex],
                                                        start, duration, room));
                        appointmentId++;
                        patientIndex++;
                        if (patientIndex >= PatientNames.Length - 1)
                            patientIndex = 1;
                    }
                MedicalAppointments = result;
            }
    
            void CreateLabels() {
                ObservableCollection<MedicalAppointmentType> result = new ObservableCollection<MedicalAppointmentType>();
                int count = AppointmentTypes.Length;
                for (int i = 0; i < count; i++) {
                    MedicalAppointmentType appointmentType = new MedicalAppointmentType();
                    appointmentType.Id = i;
                    appointmentType.Caption = AppointmentTypes[i];
                    appointmentType.Color = AppointmentTypeColors[i];
                    result.Add(appointmentType);
                }
                Labels = result;
            }
    
            MedicalAppointment CreateMedicAppointment(int appointmentId, string patientName,
                                                        DateTime start, TimeSpan duration, int room) {
                MedicalAppointment medicalAppointment = new MedicalAppointment();
                medicalAppointment.Id = appointmentId;
                medicalAppointment.StartTime = start;
                medicalAppointment.EndTime = start.Add(duration);
                medicalAppointment.Subject = patientName;
                medicalAppointment.LabelId = Labels[rnd.Next(0, 5)].Id; // Assign a custom label to an appointment
                medicalAppointment.Location = String.Format("{0}", room);
                return medicalAppointment;
            }
    
            public ObservableCollection<MedicalAppointment> MedicalAppointments { get; private set; }
            public ObservableCollection<MedicalAppointmentType> Labels { get; private set; }
    
    
            public ReceptionDeskData() {
                CreateLabels();
                CreateMedicalAppointments();
            }
        }
    }
    
See Also