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);
     });
 }
예제 #2
0
 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;
         });
     }
 }
예제 #3
0
        protected void ChangeCalendar(CalandarChanges changes)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                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))
                    {
                        var day           = start.ToString(WeekdaysFormat);
                        string showDay    = 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 = 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.Date < MinDate) || (MaxDate.HasValue && start.Date > MaxDate) || (DisableAllDates && sd == null))
                    {
                        SetButtonDisabled(buttons[i]);
                    }
                    else if (buttons[i].IsEnabled && (SelectedDates?.Select(d => d.Date)?.Contains(start.Date) ?? false))
                    {
                        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;
            });
        }