Add a checkbox inside a CellTemplate (month view)

I have a requirement that I need to place a checkbox inside each day (in month view) of a calendar.  So I created a custom template similar to this:


<calendar:SfCalendar>
<calendar:SfCalendar.MonthViewSettings>
<calendar:MonthViewSettings>
<calendar:MonthViewSettings.CellTemplate>
<DataTemplate>
<Grid>
<Label Text="{Binding DayNumber}" Grid.Row="0" Grid.Column="0" />
<CheckBox IsChecked="{Binding IsChecked}" Grid.Row="1" Grid.Column="0"  />
</Grid>
</DataTemplate>
</calendar:MonthViewSettings.CellTemplate>
</calendar:MonthViewSettings>    </calendar:SfCalendar.MonthViewSettings> </calendar:SfCalendar>

It renders great, and the checkbox is checked when it is supposed to be based on the view model that I have bound to the calendar.  However, I can't check the checkbox, presumably because the action of the Tap event of the cell won't allow the embedded controls to be tapped.  So, tapping on the checkbox doesn't actually do anything...


So then I thought I could perhaps use the OnCalendarTapped event on the calendar to figure determine which date was tapped on (which works) and somehow use THAT to check the checkbox within the cell template for the given date.  But, there doesn't appear to be anyway to do that?


Any suggestions on how to make the checkbox clickable???  Or use the OnCalendarTapped event to fire the CheckedChanged event of the checkbox?  I thought about possibly setting up a trigger but wasn't successful there either...


Thanks!


7 Replies

MS Muniappan Subramanian Syncfusion Team December 20, 2021 11:51 AM UTC

Hi Mike, 
 
Thank you for using Syncfusion products. 
 
Based on the shared information we have checked your requirement “Add a checkbox inside a CellTemplate (month view)”. You can achieve your requirement by using “OnMonthCellLoaded “event in SfCalendar. we have prepared a sample for the same, please find the sample by the following link. 
 
Code Snippet: 
private void Calendar_OnMonthCellLoaded(object sender, MonthCellLoadedEventArgs e) 
{ 
                var model = new ViewModel(); 
                model.DayNumber = e.Date.Day.ToString(); 
 
                if (calendar.SelectedDate.Value.Date == e.Date.Date && tappedDate != DateTime.MinValue) 
                { 
                                model.IsChecked = true; 
                } 
                else 
                { 
                                model.IsChecked = false; 
                } 
 
                e.CellBindingContext = model; 
} 
 
 
We hope this helps. Please let if you if you have any concern. 
 
Regards, 
Muniappan S 



ML Mike Luken December 22, 2021 08:46 AM UTC

Thanks for the reply!  


This example doesn't quite seem to work as expected....


When I try to incorporate your example into my code, I find that the OnMonthCellLoaded is called BEFORE the OnCalendarTapped event.


So in your example, in Calendar_OnCalendarTapped, the tappedDate is set AFTER the model is already bound to the cell's CellBindingContext.  


So it KIND of works, but you have to click on it a couple of times to get the expected results...


If the OnCalendarTapped event was executed prior to the OnMonthCellLoaded event when a cell was tapped, this would work perfect....


How is it in your example the OnCalendarTapped is called first, when in my working code it is the other way around?  Which is supposed to be called first?


Thanks



SS SaiGanesh Sakthivel Syncfusion Team December 23, 2021 12:07 PM UTC

Hi Mike, 
 
Currently, we are analyzing the reported scenario from our end. We will update you the further details on December 28, 2021. We appreciate the patience until then. 
 
Regards,
SaiGanesh Sakthivel
 



SS SaiGanesh Sakthivel Syncfusion Team December 28, 2021 02:01 PM UTC

Hi Mike,  
  
Currently, we are analyzing the reported scenario in our source level. We will update you the further details on December 30, 2021. We appreciate the patience until then.  
  
Regards,
SaiGanesh Sakthivel
  



SS SaiGanesh Sakthivel Syncfusion Team December 30, 2021 04:52 PM UTC

Hi Mike,

#Regarding [UWP, Android] trigger the CalendarTapped event before the OnMonthcellLoaded event
we have logged issue report for the same. We will fix the issue and include the issue fix in our upcoming Weekly Nuget release which is expected to roll out on January 18, 2022. We appreciate your patience until then.

You can track the status of this report through the following feedback link,

Note: The provided feedback link is private, you need to login to view this feedback.

Regards,
SaiGanesh Sakthivel




SS SaiGanesh Sakthivel Syncfusion Team January 18, 2022 01:44 PM UTC

Hi Mike, 
 
#Regarding [UWP, Android] trigger the CalendarTapped event before the OnMonthcellLoaded event 
We have fixed the reported issue but it takes more time for testing is longer than we expected. Also due to the stability of the control, we are not including this in this weekly nuget.   
But assuredly, we will include it in our upcoming weekly nuget January 25, 2022. We will let you once nuget gets published and appreciate your patience until then.  
  
Regards,
SaiGanesh Sakthivel
  



SS SaiGanesh Sakthivel Syncfusion Team January 25, 2022 04:35 PM UTC

Hi Mike, 
 
#Regarding [UWP, Android] trigger the CalendarTapped event before the OnMonthcellLoaded event
We have fixed the reported fix from our end. As the changes are in testing phase, we have prepared the custom assemblies including the fix. Before installing the custom assemblies, kindly remove bin and obj folders from all the projects of solution and clear NuGet cache.
 
   
Please refer our following KB document to clear nuget cache.    
   
Custom Assemblies:  
    
Please refer to the following KB documentation about How to configure the custom assembly       
   
Disclaimer:           
Please note that we have created this custom assemblies with version (19.4.0.47) specifically to include the issue. We will include the issue fix in our upcoming weekly nuget release. We appreciate your patience until then.    
   
Regards,          
SaiGanesh Sakthivel 


Loader.
Up arrow icon