How to Change the Selection Shape in the .NET MAUI Calendar (SfCalendar)?
In the Syncfusion® .NET MAUI Calendar control, you can change the selection shape using the SelectionShape property of SfCalendar.
Step 1: Add the Button control and the SfCalendar control to your layout, as shown in the following code sample.
XAML
<ContentPage.Behaviors> <local:CalendarBehavior /> </ContentPage.Behaviors> <ContentPage.Content> <Grid RowDefinitions="0.1*, 0.9*"> <Button x:Name="selectionShapeButton" HorizontalOptions="Center" VerticalOptions="Center" /> <calendar:SfCalendar Grid.Row="1" x:Name="calendar" /> </Grid> </ContentPage.Content>
Step 2: Use the Clicked event of the Button to change the SfCalendar’s SelectionShape, as demonstrated in the following code sample.
C#
public class CalendarBehavior : Behavior<ContentPage> { private SfCalendar calendar; private Button selectionShapeButton; protected override void OnAttachedTo(ContentPage bindable) { base.OnAttachedTo(bindable); this.calendar = bindable.FindByName<SfCalendar>("calendar"); this.selectionShapeButton = bindable.FindByName<Button>("selectionShapeButton"); this.selectionShapeButton.Text = "SelectionShape: " + this.calendar.SelectionShape.ToString(); this.selectionShapeButton.Clicked += SelectionShapeButton_Clicked; } private void SelectionShapeButton_Clicked(object sender, EventArgs e) { if (this.calendar.SelectionShape == CalendarSelectionShape.Circle) { this.calendar.SelectionShape = CalendarSelectionShape.Rectangle; this.selectionShapeButton.Text = "SelectionShape: " + this.calendar.SelectionShape.ToString(); } else { this.calendar.SelectionShape = CalendarSelectionShape.Circle; this.selectionShapeButton.Text = "SelectionShape: " + this.calendar.SelectionShape.ToString(); } } protected override void OnDetachingFrom(ContentPage bindable) { base.OnDetachingFrom(bindable); if (this.selectionShapeButton != null) { this.selectionShapeButton.Clicked -= SelectionShapeButton_Clicked; } this.selectionShapeButton = null; this.calendar = null; } }
The SfCalendar control supports two selection shapes: Rectangle and Circle.
Download the complete sample on GitHub
Output
When using the ‘Rectangle’ selection shape in the SfCalendar
When using the ‘Circle’ selection shape in the SfCalendar
Conclusion
I hope you enjoyed learning how to change the selection shape 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!