Articles in this section

How to restrict year view navigation in the .NET MAUI Calendar (SfCalendar)?

In the Syncfusion® .NET MAUI Calendar control, you can restrict the year view navigation by setting the SfCalendar’s AllowViewNavigation property to false.

 

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="allowNavigationButton"
                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 AllowViewNavigation property’s value to enable or disable the view navigation in the SfCalendar.

 

C#

public class CalendarBehavior : Behavior<ContentPage>
{
    private SfCalendar calendar;
    private Button allowNavigationButton;
 
    protected override void OnAttachedTo(ContentPage bindable)
    {
        base.OnAttachedTo(bindable);
        this.calendar = bindable.FindByName<SfCalendar>("calendar");
        this.calendar.AllowViewNavigation = true;
        this.allowNavigationButton = bindable.FindByName<Button>("allowNavigationButton");
        this.allowNavigationButton.Text = this.calendar.AllowViewNavigation ? "Disable view navigation" : "Enable view navigation";
        this.allowNavigationButton.Clicked += AllowNavigationButton_Clicked;
    }
 
    private void AllowNavigationButton_Clicked(object sender, EventArgs e)
    {
        if (this.calendar.AllowViewNavigation)
        {
            this.calendar.AllowViewNavigation = false;
            this.allowNavigationButton.Text = "Enable view navigation";
        }
        else
        {
            this.calendar.AllowViewNavigation = true;
            this.allowNavigationButton.Text = "Disable view navigation";
        }
    }
 
    protected override void OnDetachingFrom(ContentPage bindable)
    {
        base.OnDetachingFrom(bindable);
        if (this.allowNavigationButton != null)
        {
            this.allowNavigationButton.Clicked -= AllowNavigationButton_Clicked;
        }
 
        this.allowNavigationButton = null;
        this.calendar = null;
    }
}

 

Download the complete sample on GitHub


 

Output

 

View navigation restriction in Syncfusion .NET MAUI Calendar

 

Conclusion

 

I hope you enjoyed learning how to restrict the year view navigation 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 forumsDirect-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)
Access denied
Access denied