How to refresh the calendar items from MVVM

Hallo,

how can I refresh the calendar from MVVM after the items changed. I trigger an OnAppearing event, when I move to a calendar page, where the calendar is shown. The code loading the new data in the CalendarEventCollection, but the calendar is not refreshing. The page where the calendar is shown, was already loaded at startup and the events are showing fine.


The same code I call at start page the first time the page loads and fills the calendar with the events.


IN THE VIEWMODEL:


public CalendarEventCollection CalendarInlineEvents { get; set; } = new CalendarEventCollection();


       private async void GetCalendarData()

        {

            var calendarData = await App.Database.SelectTrackListAsync();

            int count = calendarData.Count;

            if (count > 0 )

            {

                CalendarInlineEvents.Clear();

                foreach (var _calendarData in calendarData)

                {

                    CalendarInlineEvents.Add(new CalendarInlineEvent() {Subject = _calendarData.EventName, StartTime = _calendarData.EventDateTimeStart, EndTime = _calendarData.EventDateTimeStart, Color = Color.Blue });

                }

            }

        }

Thanks,


Markus



5 Replies 1 reply marked as answer

SS SaiGanesh Sakthivel Syncfusion Team August 23, 2021 12:01 PM UTC

Hi Markus, 
 
Thank you for contacting syncfusion support. 
 
#Regarding How to refresh the calendar items from MVVM 
We would like to inform you that we have already documentation about ‘How to refresh the calendar items from MVVM’ in our Syncfusion Knowledge base in our website. Please refer to the following KB link for your reference. 
 
  
Please let us know if you have any concern. 
 
Regards,
SaiGanesh Sakthivel
 



MA Markus replied to SaiGanesh Sakthivel August 23, 2021 12:19 PM UTC

Hallo  SaiGanesh ,


thank you for your reply, I was reading this article, I was hopping for a solution, without a button click

Thanks,


Makrus



SS SaiGanesh Sakthivel Syncfusion Team August 24, 2021 10:42 AM UTC

Hi Markus, 
 
Thank you for the update. 
 
#Regarding How to refresh the calendar items from MVVM 
We have checked the reported query from our end. you can achieve your requirement with help of OnMonthChangedCommand property in the Calendar. Please refer to the following code snippet for your reference. 
 
Code Snippet 
<calendar:SfCalendar x:Name="calendar" 
                    DataSource="{Binding Appointments}" 
                    MonthChangedCommand="{Binding OnMonthChanged}"> 
 
In ViewModel Class 
public ICommand OnMonthChanged { get; set; } 

public ViewModel() 
{ 
    OnMonthChanged = new Command<MonthChangedEventArgs>(MonthChanged); 
} 

private void MonthChanged(MonthChangedEventArgs obj) 
{ 
    var calender = obj.Calendar; 
    calender.Refresh(); 
} 

please refer to the tested sample in the following link for your reference.
 
 
Please let us know if you have any concerns. 
 
Regards,
SaiGanesh Sakthivel



MA Markus August 24, 2021 07:28 PM UTC

Hi  SaiGanesh ,


thanks, I get it working now. I 


        private void MonthChanged(MonthChangedEventArgs obj)

        {

            GetCalendarData(); // clear & add CalendarEventCollection before refresh calenevents

            var calender = obj.Calendar;

            calender.Refresh();

        }


Thanks :)


Marked as answer

SS SaiGanesh Sakthivel Syncfusion Team August 25, 2021 06:26 AM UTC

Hi Markus, 
 
Thank you for the update. 
 
We are glad to know that our solution meets your requirement. Please let us know if you need any further assistance. 
 
Regards,
SaiGanesh Sakthivel


Loader.
Up arrow icon