question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Assigning templates to selected individual days

See original GitHub issue

Hi,

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:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ME-MarvinEcommented, Mar 11, 2022

No problem, I’ll keep the issue open until I make an example of how to do this in the sample app.

0reactions
LukasBritscommented, Mar 24, 2022

Great! Thanks again for the assist.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build a template and automatically assign new due dates ...
Hello, I'm currently working on building a template that we'll use to ... single project and assign specific dates as it takes 90...
Read more >
Custom Template - assign owner/date when creating new ...
Hello, I've created a board template with multiple tasks in groups - two columns are a date (dead line) and a responsible person...
Read more >
Assigning due dates in a template - Tips and Tricks
I have created an onboarding template for new hires in my office. Is there a way that dates can be assigned from the...
Read more >
Can't assign shipping templates to new manual listings
Yesterday and today I am unable to assign shipping templates to new ... Go to Manage Inventory page and assign templates to selected...
Read more >
Understanding Amazon shipping templates - YouTube
Understanding Amazon shipping templates Learn about your options for shipping templates on the Shipping Settings page in Seller Central.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found