Example #1
0
        protected void SetButton(CalendarButton b, bool isFirst = false, bool isLast = false)
        {
            if (!SelectedDates.Contains(b.Date.Value.Date))
            {
                SelectedDates.Add(b.Date.Value.Date);
            }

            var spD = SpecialDates?.FirstOrDefault(s => s.Date.Date == b.Date.Value.Date);

            SetButtonSelected(b, spD, isFirst, isLast);
        }
Example #2
0
        protected void ResetButton(CalendarButton b)
        {
            if (b.Date.HasValue)
            {
                SelectedDates?.Remove(b.Date.Value.Date);
            }
            var spD = SpecialDates?.FirstOrDefault(s => s.Date.Date == b.Date.Value.Date);

            SetButtonNormal(b);
            if (spD != null)
            {
                SetButtonSpecial(b, spD);
            }
        }
Example #3
0
        protected void SetButtonNormal(CalendarButton button)
        {
            button.BackgroundPattern = null;
            button.BackgroundImage   = null;

            Device.BeginInvokeOnMainThread(() =>
            {
                button.IsEnabled       = true;
                button.IsSelected      = false;
                button.FontSize        = DatesFontSize;
                button.BorderWidth     = BorderWidth;
                button.BorderColor     = BorderColor;
                button.FontFamily      = button.IsOutOfMonth? DatesFontFamilyOutsideMonth : DatesFontFamily;
                button.BackgroundColor = button.IsOutOfMonth ? DatesBackgroundColorOutsideMonth : DatesBackgroundColor;
                button.TextColor       = button.IsOutOfMonth ? DatesTextColorOutsideMonth : DatesTextColor;
                button.FontAttributes  = button.IsOutOfMonth ? DatesFontAttributesOutsideMonth : DatesFontAttributes;
                button.IsEnabled       = ShowNumOfMonths == 1 || !button.IsOutOfMonth;
            });
        }
Example #4
0
 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;
         });
     }
 }
Example #6
0
 protected void SetButtonDisabled(CalendarButton button)
 {
     Device.BeginInvokeOnMainThread(() =>
     {
         button.BackgroundPattern = null;
         button.BackgroundImage   = null;
         button.FontSize          = DisabledFontSize;
         button.BorderWidth       = DisabledBorderWidth;
         button.BorderColor       = DisabledBorderColor;
         button.BackgroundColor   = DisabledBackgroundColor;
         button.TextColor         = DisabledTextColor;
         button.FontAttributes    = DisabledFontAttributes;
         button.FontFamily        = DisabledFontFamily;
         if (Device.RuntimePlatform == Device.UWP)
         {
             button.IsEnabled = true;
         }
         else
         {
             button.IsEnabled = false;
         }
         button.IsSelected = false;
     });
 }
Example #7
0
        public Calendar()
        {
            TitleLeftArrow = new CalendarButton
            {
                FontAttributes    = FontAttributes.None,
                BackgroundColor   = Color.Transparent,
                BackgroundImage   = FileImageSource.FromFile((Device.RuntimePlatform == Device.UWP) ? "Assets/ic_arrow_left_normal.png" : "ic_arrow_left_normal") as FileImageSource,
                HeightRequest     = 48,
                WidthRequest      = 48,
                Margin            = new Thickness(24, 0, 0, 0),
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.End
            };

            TitleLabel = new Label {
                FontSize = 24,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center,
                FontAttributes          = FontAttributes.None,
                TextColor         = Color.Black,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Text          = string.Empty,
                LineBreakMode = LineBreakMode.NoWrap
            };

            TitleRightArrow = new CalendarButton
            {
                FontAttributes    = FontAttributes.None,
                BackgroundColor   = Color.Transparent,
                HeightRequest     = 48,
                WidthRequest      = 48,
                Margin            = new Thickness(0, 0, 24, 0),
                BackgroundImage   = FileImageSource.FromFile((Device.RuntimePlatform == Device.UWP) ? "Assets/ic_arrow_right_normal.png" : "ic_arrow_right_normal") as FileImageSource,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Start
            };

            MonthNavigationLayout = new StackLayout
            {
                Padding         = 0,
                VerticalOptions = LayoutOptions.Start,
                Orientation     = StackOrientation.Horizontal,
                HeightRequest   = 50,
                Children        = { TitleLeftArrow, TitleLabel, TitleRightArrow }
            };

            ContentView = new StackLayout
            {
                Padding     = 0,
                Orientation = StackOrientation.Vertical
            };

            MainView = new StackLayout {
                Padding     = 0,
                Orientation = StackOrientation.Vertical,
                Children    = { MonthNavigationLayout, ContentView }
            };

            TitleLeftArrow.Clicked  += LeftArrowClickedEvent;
            TitleRightArrow.Clicked += RightArrowClickedEvent;
            dayLabels        = new List <Label>(7);
            weekNumberLabels = new List <Label>(6);
            buttons          = new List <CalendarButton>(42);
            MainCalendars    = new List <Grid>(1);
            WeekNumbers      = new List <Grid>(1);

            CalendarViewType = DateTypeEnum.Normal;
            YearsRow         = 4;
            YearsColumn      = 4;
        }
Example #8
0
        public void ShowMonths()
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                Content = null;
                ContentView.Children.Clear();
                var columDef = new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                };
                var rowDef = new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star)
                };
                var details = new Grid {
                    VerticalOptions = LayoutOptions.CenterAndExpand, RowSpacing = 0, ColumnSpacing = 0, Padding = 1, BackgroundColor = BorderColor
                };
                details.ColumnDefinitions = new ColumnDefinitionCollection {
                    columDef, columDef, columDef
                };
                details.RowDefinitions = new RowDefinitionCollection {
                    rowDef, rowDef, rowDef, rowDef
                };
                for (int r = 0; r < 4; r++)
                {
                    for (int c = 0; c < 3; c++)
                    {
                        var b = new CalendarButton
                        {
                            HorizontalOptions = LayoutOptions.CenterAndExpand,
                            VerticalOptions   = LayoutOptions.CenterAndExpand,
                            Text            = DateTimeFormatInfo.CurrentInfo.MonthNames[(r * 3) + c],
                            Date            = new DateTime(StartDate.Year, (r * 3) + c + 1, 1).Date,
                            BackgroundColor = DatesBackgroundColor,
                            TextColor       = DatesTextColor,
                            FontSize        = DatesFontSize,
                            BorderWidth     = BorderWidth,
                            BorderColor     = BorderColor,
                            FontAttributes  = DatesFontAttributes,
                            WidthRequest    = ContentView.Width / 3 - BorderWidth,
                            HeightRequest   = ContentView.Height / 4 - BorderWidth
                        };

                        b.Clicked += (sender, e) =>
                        {
                            MonthYearButtonCommand?.Execute((sender as CalendarButton).Date.Value);
                            MonthYearButtonClicked?.Invoke(sender, new DateTimeEventArgs {
                                DateTime = (sender as CalendarButton).Date.Value
                            });
                            if (EnableTitleMonthYearView)
                            {
                                StartDate = (sender as CalendarButton).Date.Value;
                                PrevMonthYearView();
                            }
                        };

                        details.Children.Add(b, c, r);
                    }
                }
                details.WidthRequest  = w;
                details.HeightRequest = h;
                ContentView.Children.Add(details);
                CalendarViewType          = DateTypeEnum.Month;
                TitleLeftArrow.IsVisible  = false;
                TitleRightArrow.IsVisible = false;
                Content = MainView;
            });
        }
 public void ShowYears() => Device.BeginInvokeOnMainThread(() =>
 {
     Content = null;
     contentView.Children.Clear();
     yearButtons.Clear();
     var columDef = new ColumnDefinition {
         Width = new GridLength(1, GridUnitType.Star)
     };
     var rowDef = new RowDefinition {
         Height = new GridLength(1, GridUnitType.Star)
     };
     var details = new Grid {
         VerticalOptions = LayoutOptions.CenterAndExpand, RowSpacing = 0, ColumnSpacing = 0, Padding = 1, BackgroundColor = BorderColor
     };
     details.ColumnDefinitions = new ColumnDefinitionCollection {
         columDef, columDef, columDef, columDef
     };
     details.RowDefinitions = new RowDefinitionCollection {
         rowDef, rowDef, rowDef, rowDef
     };
     for (var r = 0; r < YearsRow; r++)
     {
         for (var c = 0; c < YearsColumn; c++)
         {
             var t = (r * YearsColumn) + c + 1;
             var b = new CalendarButton
             {
                 HorizontalOptions = LayoutOptions.CenterAndExpand,
                 VerticalOptions   = LayoutOptions.CenterAndExpand,
                 Text            = string.Format("{0}", StartDate.Year + (t - (YearsColumn * YearsRow / 2))),
                 Date            = new DateTime(StartDate.Year + (t - (YearsColumn * YearsRow / 2)), StartDate.Month, 1).Date,
                 BackgroundColor = DatesBackgroundColor,
                 TextColor       = DatesTextColor,
                 FontSize        = DatesFontSize,
                 FontAttributes  = DatesFontAttributes,
                 BorderWidth     = BorderWidth,
                 BorderColor     = BorderColor,
                 WidthRequest    = (contentView.Width / YearsRow) - BorderWidth,
                 HeightRequest   = contentView.Height / YearsColumn - BorderWidth
             };
             b.Clicked += (sender, e) =>
             {
                 MonthYearButtonCommand?.Execute((sender as CalendarButton).Date.Value);
                 MonthYearButtonClicked?.Invoke(sender, new DateTimeEventArgs {
                     DateTime = (sender as CalendarButton).Date.Value
                 });
                 if (EnableTitleMonthYearView)
                 {
                     StartDate = (sender as CalendarButton).Date.Value;
                     PrevMonthYearView();
                 }
             };
             yearButtons.Add(b);
             details.Children.Add(b, c, r);
         }
     }
     details.WidthRequest  = w;
     details.HeightRequest = h;
     contentView.Children.Add(details);
     CalendarViewType          = DateTypeEnum.Year;
     TitleLeftArrow.IsVisible  = true;
     TitleRightArrow.IsVisible = true;
     Content = mainView;
 });