Articles in this section
Category / Section

How to Select Previous or Next Dates Based on the Selected Date in the .NET MAUI Calendar (SfCalendar)?

2 mins read

In the Syncfusion .NET MAUI Calendar, select the previous and next dates based on the selected date using the SelectionChanged event of the SfCalendar.

 

Add the SfCalendar control in your view page and set the SelectionMode as Range as shown in the following code sample.

 

XAML

<ContentPage.Content>
    <calendar:SfCalendar x:Name="calendar"
                         SelectionMode="Range">
        <calendar:SfCalendar.Behaviors>
            <local:CalendarBehavior />
        </calendar:SfCalendar.Behaviors>
    </calendar:SfCalendar>
</ContentPage.Content>

 

In the SelectionChanged event of the SfCalendar, get the start date of the SelectedDateRange using the previous and next dates of the selected date as shown in the following code sample.

 

C#

private void Calendar_SelectionChanged(object sender, CalendarSelectionChangedEventArgs e)
{
    if (this.calendar.SelectedDateRange != null)
    {
        var dateRange = (CalendarDateRange)e.NewValue;
        if (dateRange.EndDate == null)
        {
            dateRange.EndDate = dateRange.StartDate.Value.AddDays(2);
            dateRange.StartDate = dateRange.StartDate.Value.AddDays(-2);
        }
    }
}

 

View the sample on GitHub

 

Output:

 

Previous and next dates selection in Syncfusion .NET MAUI Calendar

 

Conclusion

I hope you enjoyed learning how to select the previous and next dates based on the selected date in the .NET MAUI Calendar (SfCalendar).

Refer to our .NET MAUI Calendar’s feature tour page to learn about its other groundbreaking feature representations. You can explore our .NET MAUI Calendar documentation to understand how to present and manipulate data.

For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion, try our 30-day free trial to check out our .NET MAUI Calendar and other .NET MAUI components.

Please let us know in the following comments section if you have any queries or require clarifications. Contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied