I've tried a few things already but I simply cannot get the Scheduler
to show my created custom appointments even though I can see all of
them being fetched from the database (using Sqlite). I've tried binding through XAML,
with a ViewModel and using your examples but nothing works.
This is my source now:
XAML
<scheduler:SfScheduler x:Name="Scheduler"
View="Month"
ShowWeekNumber="True"
FirstDayOfWeek="Monday"
TodayHighlightBrush="Orange"
DoubleTapped="Scheduler_DoubleTapped">
</scheduler:SfScheduler>
Model
public class Appointment
{
[PrimaryKey, AutoIncrement, Unique]
public int ID { get; set; }
public DateTime From { get; set; }
public DateTime To { get; set; }
public bool AllDay { get; set; }
public string EventName { get; set; }
public string DescriptionNotes { get; set; }
}
Codebehind
public SchedulerTest()
{
InitializeComponent();
conn.CreateTable<Appointment>();
SchedulerAppointmentMapping appointmentMapping = new SchedulerAppointmentMapping
{
Subject = "EventName",
StartTime = "From",
EndTime = "To",
IsAllDay = "AllDay",
Notes = "DescriptionNotes"
};
this.Scheduler.AppointmentMapping = appointmentMapping;
BindScheduler();
}
private void BindScheduler()
{
// Creating an instance for the scheduler appointment collection.
ObservableCollection<Appointment> appointmentSource = conn.Table<Appointment>().ToObservableCollection();
//Adding the scheduler appointment collection to the AppointmentsSource of .NET MAUI Scheduler.
Scheduler.AppointmentsSource = appointmentSource;
}
Seems it had something to do with Month view. When I changed to Week I could see the Appointments so I added
<scheduler:SfScheduler.MonthView>
<scheduler:SchedulerMonthView AppointmentDisplayMode="Indicator"/>
</scheduler:SfScheduler.MonthView>
And now they show up.
Hi Christian
#Regarding Fetch the appointment from the SQlite database
We could not replicate the reported scenario from our end. We have prepared the sample as per the information and checked the sample from our side. Please refer to the following steps for your reference.
Step 1: Create the Database
public class SchedulerDatabase { readonly SQLiteConnection _database;
public SchedulerDatabase(string dbPath) { _database = new SQLiteConnection(dbPath); _database.CreateTable<Appointment>(); }
//Get the list of appointments from the database public List<Appointment> GetSchedulerAppointment() { return _database.Table<Appointment>().ToList(); }
//Insert an appointment in the database public int SaveSchedulerAppointmentAsync(Appointment appointment) { if (appointment == null) { throw new Exception("Null"); }
return _database.Insert(appointment); }
//Delete an appointment in the database public int DeleteSchedulerAppointmentAsync(Appointment appointment) { return _database.Delete(appointment); } } |
Step 2: Initialize the database in the App.cs
public static SchedulerDatabase Database { get { if (database == null) { database = new SchedulerDatabase(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SchedulerDatabase.db3")); } return database; } } |
Step 3: Fetch the data and set to the scheduler AppointmentSource
public MainPage() { InitializeComponent(); CreateTabele(); SchedulerAppointmentMapping appointmentMapping = new SchedulerAppointmentMapping { Subject = "EventName", StartTime = "From", EndTime = "To", IsAllDay = "AllDay", Notes = "DescriptionNotes" };
this.Scheduler.AppointmentMapping = appointmentMapping; this.Scheduler.AppointmentsSource = App.Database.GetSchedulerAppointment(); }
private void CreateTabele() { var appointments = App.Database.GetSchedulerAppointment(); if (appointments.Count == 0) { var todoItem = new Appointment() { From = DateTime.Today.AddHours(10), To = DateTime.Today.AddHours(12), AllDay = false, DescriptionNotes = "Meeting", EventName = "Annual", ID = 1 }; App.Database.SaveSchedulerAppointmentAsync(todoItem); } } |
Please refer to the tested sample in the following locations.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SchedulerMAUI-2111716840
Please check the sample and let us know if you still facing the same issue? If not, please modify the sample based on your scenario and revert us back with the following details,
Share the issue replication steps and video.
It will be helpful for us to check on it and provide you with the solution as soon as possible.
Regards,
SaiGanesh Sakthivel