How to Handle Long Press Callback on Date Selection in the .NET MAUI Calendar (SfCalendar)?
In the Syncfusion® .NET MAUI Calendar control, you can handle the long press callback on date selection using the LongPressed event of the SfCalendar.
Step 1: Add the SfCalendar control to your layout, as shown in the following code sample.
XAML
<calendar:SfCalendar x:Name="calendar"> <calendar:SfCalendar.Behaviors> <local:CalendarBehavior /> </calendar:SfCalendar.Behaviors> </calendar:SfCalendar>
Step 2: Implement the LongPressed event in the CalendarBehavior class, as demonstrated in the following C# code sample:
C#
public class CalendarBehavior : Behavior<SfCalendar> { private SfCalendar calendar; protected override void OnAttachedTo(SfCalendar bindable) { base.OnAttachedTo(bindable); this.calendar = bindable; this.calendar.LongPressed += Calendar_LongPressed; } private void Calendar_LongPressed(object sender, CalendarLongPressedEventArgs e) { App.Current.MainPage.DisplayAlert("DateCellHold Response", "DateCell " + e.Date.Day + " has been long pressed", "Ok"); } protected override void OnDetachingFrom(SfCalendar bindable) { base.OnDetachingFrom(bindable); if (this.calendar != null) { this.calendar.LongPressed -= Calendar_LongPressed; } this.calendar = null; } }
Download the complete sample on GitHub
Output
Conclusion
I hope you enjoyed learning how to handle the long press callback on date selection in the .NET MAUI Calendar (SfCalendar).
You can refer to our .NET MAUI Calendar’s feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI Calendar documentation to understand how to present and manipulate data.
For current customers, you can check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our .NET MAUI Calendar and other .NET MAUI components.
If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!