Assigning templates to selected individual days
See original GitHub issueHi,
I’ve been playing around with XCalendar and it’s been fun so far.
My consideration is to use it for an event manager. Everything that I need has been sorted out, but there’s one thing that I’m struggling with. Is there a way to change individual days’ templates based on certain conditions e.g. a list of dates? The reason is that I’d like to display a simple frame on days that have events scheduled. So far I’ve been able to get the frame to display based on properties within the CalendarDayView (e.g. IsCurrentMonth, IsEnabled etc.) but I seem to need a way to access it from code, which I haven’t been able to figure out.
What I am trying right now is using a template selector but I realize this might not be a viable approach.
Please excuse me if this is a simple question as I am relatively new to Xamarin. Great project btw!
<ContentPage.Resources>
<DataTemplate x:Key="eventCalendarDayViewTemplate"
x:DataType="{x:Type xcModels:CalendarDay}">
<xc:CalendarDayView x:Name="dayCalendar"
TodayTextColor="Orange"
TodayBorderColor="Transparent"
TodayBackgroundColor="Transparent"
CornerRadius="10"
CalendarView="{Binding ., Source={x:Reference MyCalendar}}"
DateTime="{Binding DateTime}"
SelectedBackgroundColor="Transparent"
SelectedTextColor="Black"
ControlTemplate="{StaticResource CalendarViewControlTemplate}">
</xc:CalendarDayView>
</DataTemplate>
<DataTemplate x:Key="genericCalendarDayViewTemplate"
x:DataType="{x:Type xcModels:CalendarDay}">
<xc:CalendarDayView x:Name="dayCalendar"
TodayTextColor="Orange"
TodayBorderColor="Transparent"
TodayBackgroundColor="Transparent"
CornerRadius="10"
CalendarView="{Binding ., Source={x:Reference MyCalendar}}"
DateTime="{Binding DateTime}"
SelectedBackgroundColor="Transparent"
SelectedTextColor="Black">
</xc:CalendarDayView>
</DataTemplate>
<ControlTemplate x:Key="CalendarViewControlTemplate">
<Grid>
<ContentPresenter Margin="0,0,0,5" />
<Frame x:Name="SelectedEventIndicator"
IsVisible="{TemplateBinding IsEnabled}"
Margin="0"
Padding="0"
CornerRadius="100"
HasShadow="False"
HeightRequest="6"
HorizontalOptions="Center"
VerticalOptions="End"
WidthRequest="20"
BackgroundColor="#4ABC5F">
</Frame>
</Grid>
</ControlTemplate>
<selector:CalendarDayTemplateSelector x:Key="calendarDayTemplateSelector"
EventCalendarDayViewTemplate="{StaticResource eventCalendarDayViewTemplate}"
GenericCalendarDayViewTemplate="{StaticResource genericCalendarDayViewTemplate}" />
</ContentPage.Resources>
<StackLayout>
<Frame Margin="25"
Padding="0"
CornerRadius="10"
HasShadow="False"
BorderColor="Transparent"
BackgroundColor="Transparent">
<StackLayout>
<xc:CalendarView x:Name="MyCalendar"
BackgroundColor="WhiteSmoke"
NavigationBackgroundColor="#4ABC5F"
SelectionType="Single"
SelectionAction="Replace"
DateSelectionChanged="CalendarView_DateSelectionChanged"
DayTemplate="{StaticResource calendarDayTemplateSelector}">
</xc:CalendarView>
</StackLayout>
</Frame>
<StackLayout>
<Frame Margin="25"
Padding="0"
CornerRadius="10"
HasShadow="False"
BorderColor="Transparent"
BackgroundColor="Transparent">
<Label x:Name="lblDateSelected"
FontSize="30"
TextColor="DarkGray"
Text="Test text"
HorizontalOptions="Center" />
</Frame>
</StackLayout>
</StackLayout>
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)

Top Related StackOverflow Question
No problem, I’ll keep the issue open until I make an example of how to do this in the sample app.
Great! Thanks again for the assist.