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!
|
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;
} |
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