protected void SetButtonSelected(CalendarButton button, SpecialDate special, bool first = false, bool last = false) { Device.BeginInvokeOnMainThread(() => { button.BackgroundPattern = special != null ? special.BackgroundPattern : null; if (first) { button.BackgroundImage = special != null ? special.BackgroundImage : FirstSelectedBackgroundImage != null ? FirstSelectedBackgroundImage : null; } else if (last) { button.BackgroundImage = special != null ? special.BackgroundImage : LastSelectedBackgroundImage != null ? LastSelectedBackgroundImage : null; } else { if (SelectedDates.Count == 1) { button.BackgroundImage = special != null ? special.BackgroundImage : SelectedBackgroundImage != null? SelectedBackgroundImage : null; } else { button.BackgroundImage = special != null ? special.BackgroundImage : SelectedBackgroundImage != null ? SelectedRangeBackgroundImage : null; } } var defaultBackgroundColor = button.IsOutOfMonth ? DatesBackgroundColorOutsideMonth : DatesBackgroundColor; var defaultTextColor = button.IsOutOfMonth ? DatesTextColorOutsideMonth : DatesTextColor; var defaultFontAttributes = button.IsOutOfMonth ? DatesFontAttributesOutsideMonth : DatesFontAttributes; var defaultFontFamily = button.IsOutOfMonth ? DatesFontFamilyOutsideMonth : DatesFontFamily; button.IsEnabled = true; button.IsSelected = true; button.VerticalOptions = LayoutOptions.FillAndExpand; button.HorizontalOptions = LayoutOptions.FillAndExpand; button.FontSize = SelectedFontSize; button.BorderWidth = SelectedBorderWidth; button.BorderColor = SelectedBorderColor; button.BackgroundColor = SelectedBackgroundColor != Color.Default ? SelectedBackgroundColor : (special != null && special.BackgroundColor.HasValue ? special.BackgroundColor.Value : defaultBackgroundColor); button.TextColor = SelectedTextColor != Color.Default ? SelectedTextColor : (special != null && special.TextColor.HasValue ? special.TextColor.Value : defaultTextColor); button.FontAttributes = SelectedFontAttributes != FontAttributes.None ? SelectedFontAttributes : (special != null && special.FontAttributes.HasValue ? special.FontAttributes.Value : defaultFontAttributes); button.FontFamily = !string.IsNullOrEmpty(SelectedFontFamily) ? SelectedFontFamily : (special != null && !string.IsNullOrEmpty(special.FontFamily) ? special.FontFamily :defaultFontFamily); }); }
protected void SetButtonSpecial(CalendarButton button, SpecialDate special) { if (button != null) { Device.BeginInvokeOnMainThread(() => { button.BackgroundPattern = special.BackgroundPattern; button.BackgroundImage = special.BackgroundImage; if (special.FontSize.HasValue) { button.FontSize = special.FontSize.Value; } if (special.BorderWidth.HasValue) { button.BorderWidth = special.BorderWidth.Value; } if (special.BorderColor.HasValue) { button.BorderColor = special.BorderColor.Value; } if (special.BackgroundColor.HasValue) { button.BackgroundColor = special.BackgroundColor.Value; } if (special.TextColor.HasValue) { button.TextColor = special.TextColor.Value; } if (special.FontAttributes.HasValue) { button.FontAttributes = special.FontAttributes.Value; } if (!string.IsNullOrEmpty(special.FontFamily)) { button.FontFamily = special.FontFamily; } button.IsEnabled = special.Selectable; }); } }
protected void ChangeCalendar(CalandarChanges changes) { Device.BeginInvokeOnMainThread(() => { Content = null; if (changes.HasFlag(CalandarChanges.StartDate)) { TitleLabel.Text = PersianDateInfo.MonthDic[StartDate.ToPersianDateTime().Month]; //if (TitleLabels != null) //{ // var tls = StartDate.AddMonths(1); // foreach (var tl in TitleLabels) // { // (tl as Label).Text = PersianDateInfo.MonthDic[tls.Month]; // tls = tls.AddMonths(1); // } //} } var pc = new PersianCalendar(); var start = CalendarStartDate(StartDate.ToPersianDateTime()); var end = pc.GetDaysInMonth(start.Year, start.Month); var startEn = start.ToDateTime(); var beginOfMonth = false; var endOfMonth = false; for (int i = 0; i < buttons.Count; i++) { endOfMonth |= i == end; beginOfMonth |= start.Day == 1; var ddd = changes.HasFlag(CalandarChanges.StartDay); //if (i < dayLabels.Count && WeekdaysShow && changes.HasFlag(CalandarChanges.StartDay)) if (i < dayLabels.Count && WeekdaysShow) { var day = startEn.ToString(WeekdaysFormat); string showDay = PersianDateInfo.WeekDays[char.ToUpper(day.First()) + day.Substring(1).ToLower()]; dayLabels[i].Text = showDay; } //ChangeWeekNumbers(start, i); if (changes.HasFlag(CalandarChanges.All)) { buttons[i].Text = string.Format("{0}", start.Day); } else { buttons[i].TextWithoutMeasure = string.Format("{0}", start.Day); } buttons[i].Date = startEn; buttons[i].IsOutOfMonth = !(beginOfMonth && !endOfMonth); buttons[i].IsEnabled = ShowNumOfMonths == 1 || !buttons[i].IsOutOfMonth; SpecialDate sd = null; //if (SpecialDates != null) //{ // sd = SpecialDates.FirstOrDefault(s => s.Date.Date == start.Date); //} SetButtonNormal(buttons[i]); if ((MinDate.HasValue && startEn.Date < MinDate) || (MaxDate.HasValue && startEn.Date > MaxDate) || (DisableAllDates && sd == null)) { SetButtonDisabled(buttons[i]); } else if (buttons[i].IsEnabled && (SelectedDates?.Select(d => d.Date)?.Contains(startEn.Date) ?? false)) { SetButtonSelected(buttons[i], sd); } else if (sd != null) { SetButtonSpecial(buttons[i], sd); } start.AddDay(1, end); startEn = start.ToDateTime(); // if (i != 0 && (i+1) % 42 == 0) //{ // beginOfMonth = false; // endOfMonth = false; // start = CalendarStartDate(start); //} } if (DisableDatesLimitToMaxMinRange) { TitleLeftArrow.IsEnabled = !(MinDate.HasValue && CalendarStartDate(StartDate.ToPersianDateTime()).ToDateTime() < MinDate); TitleRightArrow.IsEnabled = !(MaxDate.HasValue && start.ToDateTime() > MaxDate); } Content = MainView; }); }