Hi There,
I want to load the DayTemplate according to the month displayed in the current calendar.
The DayTemplate xaml codes:
<local:ReminderTemplateSelector.TaskTemplate>
<DataTemplate>
<telerik:CalendarBorderLabel Text="{Binding Text}"
TextColor="{StaticResource AccentColor4}"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
FontAttributes="Bold">
<Label FontFamily="TelerikFontExamples"
Text=""
TextColor="{StaticResource AccentColor4}"
HorizontalTextAlignment="Center"
VerticalTextAlignment="End"
Margin="{OnPlatform Default=0, WinUI='0, 0, 0, 4'}" />
</telerik:CalendarBorderLabel>
</DataTemplate>
</local:ReminderTemplateSelector.TaskTemplate>
ReminderTemplateSelector :
public class ReminderTemplateSelector : DataTemplateSelector
{
public static readonly BindableProperty TasksProperty = BindableProperty.Create(nameof(Tasks), typeof(ReminderTemplateSelector), typeof(ReminderTemplateSelector), null);
private List<DateTime> tasks;
public ReminderTemplateSelector()
{
}
public DataTemplate TaskTemplate { get; set; }
public List<DateTime> Tasks
{
get => this.tasks;
set
{
this.tasks = value;
}
}
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
var node = item as CalendarNode;
var date = node.Date.Value;
bool hasTaskReminder = false;
if (this.tasks != null)
{
hasTaskReminder = this.tasks.Contains(date);
}
if (hasTaskReminder)
{
return this.TaskTemplate;
}
return null;
}
}
I am trying to reload the "Task" by month on OnDisplayDate event, but OnSelectTemplate executed before the date change.
It is unable to load the correct DayTemplate based on the current month changes. How should I do it?
private async void OnDisplayDateChanged(object sender, ValueChangedEventArgs<System.DateTime> e)
{
this.ReminderTemplateSelector.Tasks = LoadTask(e.NewValue);
}