diff --git a/samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml b/samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml index 769dbc0dac..5489935c64 100644 --- a/samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml +++ b/samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml @@ -49,6 +49,11 @@ + + + diff --git a/src/Avalonia.Controls/Calendar/Calendar.cs b/src/Avalonia.Controls/Calendar/Calendar.cs index b5f0795be7..c8fe0aa1ed 100644 --- a/src/Avalonia.Controls/Calendar/Calendar.cs +++ b/src/Avalonia.Controls/Calendar/Calendar.cs @@ -390,7 +390,7 @@ namespace Avalonia.Controls /// Defines the property. /// public static readonly StyledProperty WeekNumberHeaderProperty = - AvaloniaProperty.Register(nameof(WeekNumberHeader)); + AvaloniaProperty.Register(nameof(WeekNumberHeader), "#"); /// /// Gets or sets the content displayed in the week-number column header cell. diff --git a/src/Avalonia.Controls/Calendar/CalendarItem.cs b/src/Avalonia.Controls/Calendar/CalendarItem.cs index 719229afea..83a67f1435 100644 --- a/src/Avalonia.Controls/Calendar/CalendarItem.cs +++ b/src/Avalonia.Controls/Calendar/CalendarItem.cs @@ -24,7 +24,7 @@ namespace Avalonia.Controls.Primitives [TemplatePart(PART_ElementNextButton, typeof(Button))] [TemplatePart(PART_ElementPreviousButton, typeof(Button))] [TemplatePart(PART_ElementYearView, typeof(Grid))] - [PseudoClasses(":calendardisabled")] + [PseudoClasses(":calendardisabled", ":showweeknumbers")] public sealed class CalendarItem : TemplatedControl { /// @@ -632,6 +632,8 @@ namespace Avalonia.Controls.Primitives var rule = Owner?.WeekNumberRule ?? DateTimeHelper.GetCurrentDateFormat().CalendarWeekRule; var firstDayOfWeek = Owner?.FirstDayOfWeek ?? DateTimeHelper.GetCurrentDateFormat().FirstDayOfWeek; + PseudoClasses.Set(":showweeknumbers", show); + for (int i = 0; i < _weekNumberLabels.Length; i++) { DateTime firstDayOfRow = _calendar.AddDays(firstDateDisplayed, i * NumberOfDaysPerWeek); diff --git a/src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.Properties.cs b/src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.Properties.cs index 864ba86ef0..9b9418265c 100644 --- a/src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.Properties.cs +++ b/src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.Properties.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using Avalonia.Controls.Primitives; using Avalonia.Data; using Avalonia.Layout; @@ -140,6 +141,24 @@ namespace Avalonia.Controls public static readonly StyledProperty VerticalContentAlignmentProperty = ContentControl.VerticalContentAlignmentProperty.AddOwner(); + /// + /// Defines the property. + /// + public static readonly StyledProperty ShowWeekNumbersProperty = + Calendar.ShowWeekNumbersProperty.AddOwner(); + + /// + /// Defines the property. + /// + public static readonly StyledProperty WeekNumberRuleProperty = + Calendar.WeekNumberRuleProperty.AddOwner(); + + /// + /// Defines the property. + /// + public static readonly StyledProperty WeekNumberHeaderProperty = + Calendar.WeekNumberHeaderProperty.AddOwner(); + /// /// Gets a collection of dates that are marked as not selectable. /// @@ -358,5 +377,36 @@ namespace Avalonia.Controls get => GetValue(VerticalContentAlignmentProperty); set => SetValue(VerticalContentAlignmentProperty, value); } + + /// + /// Gets or sets a value indicating whether week numbers are shown in the month view + /// of the drop-down . + /// + public bool ShowWeekNumbers + { + get => GetValue(ShowWeekNumbersProperty); + set => SetValue(ShowWeekNumbersProperty, value); + } + + /// + /// Gets or sets the rule used to determine the first week of the year for week number display. + /// The default is taken from the current culture. + /// + public CalendarWeekRule WeekNumberRule + { + get => GetValue(WeekNumberRuleProperty); + set => SetValue(WeekNumberRuleProperty, value); + } + + /// + /// Gets or sets the content displayed in the week-number column header cell of the drop-down + /// . Set to a localized string such as "CW", "KW", + /// or "Wk" to give users context. Defaults to null (blank). + /// + public object? WeekNumberHeader + { + get => GetValue(WeekNumberHeaderProperty); + set => SetValue(WeekNumberHeaderProperty, value); + } } } diff --git a/src/Avalonia.Themes.Fluent/Controls/CalendarDatePicker.xaml b/src/Avalonia.Themes.Fluent/Controls/CalendarDatePicker.xaml index 395e2d514f..c500f18edf 100644 --- a/src/Avalonia.Themes.Fluent/Controls/CalendarDatePicker.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/CalendarDatePicker.xaml @@ -133,7 +133,10 @@ SelectedDate="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedDate, Mode=TwoWay}" DisplayDate="{TemplateBinding DisplayDate}" DisplayDateStart="{TemplateBinding DisplayDateStart}" - DisplayDateEnd="{TemplateBinding DisplayDateEnd}" /> + DisplayDateEnd="{TemplateBinding DisplayDateEnd}" + ShowWeekNumbers="{TemplateBinding ShowWeekNumbers}" + WeekNumberRule="{TemplateBinding WeekNumberRule}" + WeekNumberHeader="{TemplateBinding WeekNumberHeader}" /> diff --git a/src/Avalonia.Themes.Fluent/Controls/CalendarItem.xaml b/src/Avalonia.Themes.Fluent/Controls/CalendarItem.xaml index ac3ebadbb8..b06c0a9350 100644 --- a/src/Avalonia.Themes.Fluent/Controls/CalendarItem.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/CalendarItem.xaml @@ -73,9 +73,10 @@ - +