@namespace AntDesign @inherits AntDomComponentBase @using AntDesign.Internal
@{ int startYear = Calendar.Value.AddYears(-10).Year; int endYear = Calendar.Value.AddYears(10).Year; if (Calendar.ValidRange != null) { startYear = Calendar.ValidRange[0].Year; endYear = Calendar.ValidRange[1].Year; } string yearFormat = Calendar.CultureInfo.GetDateLocale().YearFormat; } @if (Calendar.Mode == DatePickerType.Month) { int startMonth = 1; int endMonth = 12; if (Calendar.ValidRange != null) { startMonth = Calendar.Value.Year == Calendar.ValidRange[0].Year ? Calendar.ValidRange[0].Month : startMonth; endMonth = Calendar.Value.Year == Calendar.ValidRange[1].Year ? Calendar.ValidRange[1].Month : endMonth; } string monthFormat = Calendar.CultureInfo.GetDateLocale().MonthFormat; } @(Calendar.CultureInfo.GetDateLocale().Month) @(Calendar.CultureInfo.GetDateLocale().Year)
@code { [CascadingParameter(Name = "PrefixCls")] public string PrefixCls { get; set; } [CascadingParameter(Name = "Calendar")] public Calendar Calendar { get; set; } private DateTime currentDate; private bool hasChangeYear = true; protected override void OnInitialized() { base.OnInitialized(); currentDate = Calendar.Value; } private void OnModeChange(string value) { Calendar.ChangePickerType(value); } private async Task OnSelectYear(string value) { int year = Convert.ToInt32(value); await Calendar.ChangeValue(DateHelper.CombineNewDate(Calendar.Value, year: year)); } private async Task OnSelectMonth(string value) { int month = Convert.ToInt32(value); await Calendar.ChangeValue(DateHelper.CombineNewDate(Calendar.Value, month: month)); } }