protected void SetButtonSpecial(CalendarButton button, SpecialDate special) { Device.BeginInvokeOnMainThread(() => { 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; } button.IsEnabled = special.Selectable; }); }
protected void ChangeCalendar(CalandarChanges changes) { if (changes.HasFlag(CalandarChanges.StartDate)) { Device.BeginInvokeOnMainThread(() => CenterLabel.Text = StartDate.ToString(TitleLabelFormat)); } var start = CalendarStartDate; var beginOfMonth = false; var endOfMonth = false; for (int i = 0; i < buttons.Count; i++) { endOfMonth |= beginOfMonth && start.Day == 1; beginOfMonth |= start.Day == 1; if (i < 7 && WeekdaysShow && changes.HasFlag(CalandarChanges.StartDay)) { labels[i].Text = start.ToString(WeekdaysFormat); } 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 = start; var isInsideMonth = beginOfMonth && !endOfMonth; SpecialDate sd = null; if (SpecialDates != null) { sd = SpecialDates.FirstOrDefault(s => s.Date.Date == start.Date); } if ((MinDate.HasValue && start < MinDate) || (MaxDate.HasValue && start > MaxDate)) { SetButtonDisabled(buttons[i]); } else if (SelectedDate.HasValue && start.Date == SelectedDate.Value.Date) { SetButtonSelected(buttons[i], isInsideMonth); } else if (sd != null) { SetButtonSpecial(buttons[i], sd); } else { SetButtonNormal(buttons[i], isInsideMonth); } start = start.AddDays(1); } }
protected void SetButtonSelected(CalendarButton button, SpecialDate special) { Device.BeginInvokeOnMainThread(() => { var defaultBackgroundColor = button.IsOutOfMonth ? DatesBackgroundColorOutsideMonth : DatesBackgroundColor; var defaultTextColor = button.IsOutOfMonth ? DatesTextColorOutsideMonth : DatesTextColor; var defaultFontAttributes = button.IsOutOfMonth ? DatesFontAttributesOutsideMonth : DatesFontAttributes; button.BackgroundPattern = special != null ? special.BackgroundPattern : null; button.IsEnabled = true; button.IsSelected = true; button.FontSize = SelectedFontSize; button.BorderWidth = SelectedBorderWidth; button.BorderColor = SelectedBorderColor; button.BackgroundColor = SelectedBackgroundColor.HasValue ? SelectedBackgroundColor.Value : (special != null && special.BackgroundColor.HasValue ? special.BackgroundColor.Value : defaultBackgroundColor); button.TextColor = SelectedTextColor.HasValue ? SelectedTextColor.Value : (special != null && special.TextColor.HasValue ? special.TextColor.Value : defaultTextColor); button.FontAttributes = SelectedFontAttributes != FontAttributes.None ? SelectedFontAttributes : (special != null && special.FontAttributes.HasValue ? special.FontAttributes.Value : defaultFontAttributes); }); }
protected void SetButtonSpecial(CalendarButton button, SpecialDate special) { if (button.IsOutOfMonth && HideSpecialOutOfMonth) { return; } 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 SetButtonSelected(CalendarButton button, SpecialDate special) { Device.BeginInvokeOnMainThread(() => { button.BackgroundPattern = special != null ? special.BackgroundPattern : null; button.BackgroundImage = special != null ? special.BackgroundImage : 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.CornerRadius = SelectedCornerRadius ?? (special != null && special.CornerRadius.HasValue ? special.CornerRadius.Value : CornerRadius); 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 ChangeCalendar(CalandarChanges changes) { Device.BeginInvokeOnMainThread(() => { OnStartRenderCalendar?.Invoke(this, EventArgs.Empty); Content = null; if (changes.HasFlag(CalandarChanges.StartDate)) { TitleLabel.Text = StartDate.ToString(TitleLabelFormat); if (TitleLabels != null) { var tls = StartDate.AddMonths(1); foreach (var tl in TitleLabels) { (tl as Label).Text = tls.ToString(TitleLabelFormat); tls = tls.AddMonths(1); } } } var start = CalendarStartDate(StartDate).Date; var beginOfMonth = false; var endOfMonth = false; for (int i = 0; i < buttons.Count; i++) { endOfMonth |= beginOfMonth && start.Day == 1; beginOfMonth |= start.Day == 1; if (i < dayLabels.Count && WeekdaysShow && changes.HasFlag(CalandarChanges.StartDay)) { SetWeekdayLabel(start, i); } 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 = start; 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 && start < MinDate) || (MaxDate.HasValue && start > MaxDate) || (DisableAllDates && sd == null)) { SetButtonDisabled(buttons[i]); } else if (buttons[i].IsEnabled && SelectedDates.Select(d => d.Date).Contains(start.Date)) { SetButtonSelected(buttons[i], sd); } else if (sd != null) { SetButtonSpecial(buttons[i], sd); } start = start.AddDays(1); if (i != 0 && (i + 1) % 42 == 0) { beginOfMonth = false; endOfMonth = false; start = CalendarStartDate(start); } } if (DisableDatesLimitToMaxMinRange) { TitleLeftArrow.IsEnabled = !(MinDate.HasValue && CalendarStartDate(StartDate).Date < MinDate); TitleRightArrow.IsEnabled = !(MaxDate.HasValue && start > MaxDate); } Content = MainView; OnEndRenderCalendar?.Invoke(this, EventArgs.Empty); }); }
protected void ChangeCalendar(CalendarChanges changes) { Device.BeginInvokeOnMainThread(() => { OnStartRenderCalendar?.Invoke(this, EventArgs.Empty); Content = null; if (changes.HasFlag(CalendarChanges.StartDate)) { TitleLabel.Text = StartDate.ToString(TitleLabelFormat); if (TitleLabels != null) { var tls = StartDate.AddMonths(1); foreach (var tl in TitleLabels) { (tl as Label).Text = tls.ToString(TitleLabelFormat); tls = tls.AddMonths(1); } } } var start = CalendarStartDate(StartDate).Date; var beginOfMonth = false; var endOfMonth = false; var hideLastRow = false; for (int i = 0; i < buttons.Count; i++) { endOfMonth |= beginOfMonth && start.Day == 1; beginOfMonth |= start.Day == 1; if (i < dayLabels.Count && WeekdaysShow && changes.HasFlag(CalendarChanges.StartDay)) { if (WeekdaysFormat.ToLower() == "d1") { dayLabels[i].Text = start.ToString("ddd").Substring(0, 1); } else if (WeekdaysFormat.ToLower() == "d2") { dayLabels[i].Text = start.ToString("ddd").Substring(0, 2); } else { dayLabels[i].Text = start.ToString(WeekdaysFormat); } } ChangeWeekNumbers(start, i); if (changes.HasFlag(CalendarChanges.All)) { buttons[i].Text = string.Format("{0}", start.Day); } else { buttons[i].TextWithoutMeasure = string.Format("{0}", start.Day); } buttons[i].Date = start; buttons[i].IsOutOfMonth = !(beginOfMonth && !endOfMonth); buttons[i].IsEnabled = ShowNumOfMonths == 1 || !buttons[i].IsOutOfMonth; if (i == 35 && buttons[i].IsOutOfMonth) { // this means that we are on the bottom row and none of the dates // in it belong to the current month we should hide this row hideLastRow = true; rows.Last().IsVisible = false; } if (i >= 35 && hideLastRow) { buttons[i].IsVisible = false; } else { if (buttons[i].IsOutOfMonth) { buttons[i].IsVisible = ShowOutOfMonthDates; } else { buttons[i].IsVisible = true; } rows.Last().IsVisible = true; } SpecialDate sd = null; if (SpecialDates != null) { sd = SpecialDates.FirstOrDefault(s => s.Date.Date == start.Date); } SetButtonNormal(buttons[i]); if ((MinDate.HasValue && start < MinDate) || (MaxDate.HasValue && start > MaxDate) || (DisableAllDates && sd == null)) { SetButtonDisabled(buttons[i]); } else if (buttons[i].IsEnabled && SelectedDates.Select(d => d.Date).Contains(start.Date)) { SetButtonSelected(buttons[i], sd); } else if (sd != null) { SetButtonSpecial(buttons[i], sd); } start = start.AddDays(1); if (i != 0 && (i + 1) % 42 == 0) { beginOfMonth = false; endOfMonth = false; start = CalendarStartDate(start); } } if (DisableDatesLimitToMaxMinRange) { TitleLeftArrow.IsEnabled = !(MinDate.HasValue && CalendarStartDate(StartDate).Date < MinDate); TitleRightArrow.IsEnabled = !(MaxDate.HasValue && start > MaxDate); } Content = MainView; OnEndRenderCalendar?.Invoke(this, EventArgs.Empty); }); }