一个跨平台插件,为 .NET 提供用于表示日历的 API,以及可完全自定义的日历控件,适用于 .NET MAUI 和 Xamarin Forms
一个跨平台插件,为 .NET 提供用于表示日历的 API,以及可完全自定义的日历控件,适用于 .NET MAUI 和 Xamarin Forms
A cross-platform plugin for .NET providing a Calendar API and DateTime extensions.
UI controls are available for Xamarin Forms and .NET MAUI, able to run on any platform the respective framework supports.
ICalendar, ICalendarDay, or IEvent.Culture/Locale property for CalendarViewFollow the discussion for moving XCalendar into the Maui Community Toolkit here.
The sample app has a flyout menu where you can access the following pages:
A page where you can modify almost every single property of the CalendarView. Perfect for a quick look, showcases, tests and experiments!
A page where you can search for examples of how to use XCalendar.
Examples include:
| Official App | Sample App |
|---|---|
public Calendar MyCalendar { get; set; } = new Calendar();public Calendar MyCalendar { get; set; } = new Calendar();xmlns:xc="clr-namespace:XCalendar.Forms.Views;assembly=XCalendar.Forms"
Alternatively, these properties can be set directly from code-behind without the use of MVVM.
)
public Calendar MyCalendar { get; set; } = new Calendar();xmlns:xc="clr-namespace:XCalendar.Maui.Views;assembly=XCalendar.Maui"
Alternatively, these properties can be set directly from code-behind without the use of MVVM.
Navigation can be performed by setting the NavigatedDate property of the Calendar.
Alternatively, navigation can be performed using the Navigate method; it takes a parameter specifying the TimeSpan to navigate by. The Calendar can handle exceptions caused by non-representable dates such as DateTime.MaxValue.AddDays(1).
Variable time units such as months can be obtained by using the'AddMonths' method on a DateTime and subtracting the result from the current date. The 'TryAdd' and 'TrySubtract' methods in DateTimeExtensions are useful if you ever plan to navigate to the bounds of the DateTime struct.
Navigation can be limited to a specific range of dates by changing the NavigationLowerBound and NavigationUpperBound properties of the Calendar.
You can specify the behaviour of the CalendarView when trying to navigate outside the bounds defined by NavigationLowerBound and NavigationUpperBound by changing the NavigationLoopMode property.
The CalendarView does not have navigation built into it by default. Instead, it exposes the BackwardsArrowCommand, BackwardsArrowCommandParameter, ForwardsArrowCommand, and ForwardsArrowCommandParameter which can be used to implement this functionality.
The CalendarView displays its navigation bar using a NavigationView. Its appearance can be changed using the NavigationViewTemplate property of the CalendarView.
You can specify what day of the week should be considered as the start by setting the StartOfWeek property of the Calendar.
For Example:
StartOfWeek is DayOfWeek.Monday, the first row of February 2022 would be 1st Feb - 7th Feb.StartOfWeek is DayOfWeek.Wednesday, the first row of February 2022 would be 26th Jan - 1st FebStartOfWeek is DayOfWeek.Sunday, the first row of February 2022 would be 31st Jan - 6th FebYou can set how many rows you want to display by changing the Rows property of the Calendar.
Alternatively, the Calendar can automatically set the Rows value to the minimum amount needed to display every week of the NavigatedDate's month. This can be done by setting the AutoRows property of the Calendar to true. You can ensure that AutoRows always uses the highest Rows value required in the year by setting the AutoRowsIsConsistent property of the Calendar to true.
For example, when the start of the week is Monday, these are the values that will be calculated using AutoRows:
| Date | Value | Value (AutoRowsIsConsistent) |
|---|---|---|
| January 2021 | 5 | 6 |
| February 2021 | 4 | 6 |
| March 2021 | 5 | 6 |
| April 2021 | 5 | 6 |
| May 2021 | 6 | 6 |
| June 2021 | 5 | 6 |
| July 2021 | 5 | 6 |
| August 2021 | 6 | 6 |
| September 2021 | 5 | 6 |
| Ocotober 2021 | 5 | 6 |
| November 2021 | 5 | 6 |
| December 2021 | 5 | 6 |
The displayed dates are stored in the DayNamesOrder property.
The value of the DayNamesOrder is automatically calculated by the Calendar based on the values of its StartOfWeek and CustomDayNamesOrder:
StartOfWeek property of the Calendar.CustomDayNamesOrder property of the Calendar is null, these default dates will be shown. CustomDayNamesOrder property of the Calendar is not null, the Calendar will cherry-pick values from these default dates, mapping their DayOfWeek to the values specified in the CustomDayNamesOrder property and shows the result.The CustomDayNamesOrder property supports duplicates and non-chronological orders, but must contain at least one value.
| StartOfWeek | DayNamesOrder | Resulting Row (January 2023 Week 1) |
|---|---|---|
| Monday | Mon, Tue, Wed, Thu, Fri, Sat, Sun | 26th Dec, 27th Dec, 28th Dec, 29th Dec, 30th Dec, 31st Dec, 1st Jan |
| Monday | Sun, Sat, Fri, Thu, Wed, Tue, Mon | 1st Jan, 31st Dec, 30th Dec, 29th Dec, 28th Dec, 27th Dec, 26th Dec |
| Monday | Wed, Fri, Mon, Thu, Sat, Sun, Tue | 28th Dec, 30th Dec, 26th Dec, 29th Dec, 31st Dec, 1st Jan, 27th Dec |
| Monday | Mon, Thu, Sun | 26th Dec, 29th Dec, 1st Jan |
| Monday | Mon, Sun, Tue Tue, Mon | 26th Dec, 1st Jan, 27th Dec, 27th Dec, 26th Dec |
| StartOfWeek | DayNamesOrder | Resulting Row (January 2023 Week 1) |
|---|---|---|
| Tuesday | Mon, Tue, Wed, Thu, Fri, Sat, Sun | 27th Dec, 28th Dec, 29th Dec, 30th Dec, 31st Dec, 1st Jan, 2nd Jan |
| Tuesday | Sun, Sat, Fri, Thu, Wed, Tue, Mon | 1st Jan, 31st Dec, 30th Dec, 29th Dec, 28th Dec, 27th Dec, 2nd Jan |
| Tuesday | Wed, Fri, Mon, Thu, Sat, Sun, Tue | 28th Dec, 30th Dec, 2nd Jan, 29th Dec, 31st Dec, 1st Jan, 27th Dec |
| Tuesday | Mon, Thu, Sun | 2nd Jan, 29th Dec, 1st Jan |
| Tuesday | Mon, Sun, Tue Tue, Mon | 2nd Jan, 1st Jan, 27th Dec, 27th Dec, 2nd Jan |
| StartOfWeek | DayNamesOrder | Resulting Row (January 2023 Week 1) |
|---|---|---|
| Wednesday | Sun, Sat, Fri, Thu, Wed, Tue, Mon | 1st Jan, 31st Dec, 30th Dec, 29th Dec, 28th Dec, 3rd Jan, 2nd Jan |
| Wednesday | Mon, Tue, Wed, Thu, Fri, Sat, Sun | 28th Dec, 29th Dec, 30th Dec, 31st Dec, 1st Jan, 2nd Jan, 3rd Jan |
| Wednesday | Wed, Fri, Mon, Thu, Sat, Sun, Tue | 28th Dec, 30th Dec, 2nd Jan, 29th Dec, 31st Dec, 1st Jan, 3rd Jan |
| Wednesday | Mon, Thu, Sun | 2nd Jan, 29th Dec, 1st Jan |
| Wednesday | Mon, Sun, Tue Tue, Mon | 2nd Jan, 1st Jan, 3rd Jan, 3rd Jan, 2nd Jan |
| StartOfWeek | DayNamesOrder | Resulting Row (January 2023 Week 1) |
|---|---|---|
| Thursday | Mon, Tue, Wed, Thu, Fri, Sat, Sun | 29th Dec, 30th Dec, 31st Dec, 1st Jan, 2nd Jan, 3rd Jan, 4th Jan |
| Thursday | Sun, Sat, Fri, Thu, Wed, Tue, Mon | 1st Jan, 31st Dec, 30th Dec, 29th Dec, 4th Jan, 3rd Jan, 2nd Jan |
| Thursday | Wed, Fri, Mon, Thu, Sat, Sun, Tue | 4th Jan, 30th Dec, 2nd Jan, 29th Dec, 31st Dec, 1st Jan, 3rd Jan |
| Thursday | Mon, Thu, Sun | 2nd Jan, 29th Dec, 1st Jan |
| Thursday | Mon, Sun, Tue Tue, Mon | 2nd Jan, 1st Jan, 3rd Jan, 3rd Jan, 2nd Jan |
| StartOfWeek | DayNamesOrder | Resulting Row (January 2023 Week 1) |
|---|---|---|
| Friday | Mon, Tue, Wed, Thu, Fri, Sat, Sun | 30th Dec, 31st Dec, 1st Jan, 2nd Jan, 3rd Jan, 4th Jan, 5th Jan |
| Friday | Sun, Sat, Fri, Thu, Wed, Tue, Mon | 1st Jan, 31st Dec, 30th Dec, 5th Ja |
暂无开放 Issues,或尚未同步最近议题。