Beispiel #1
0
        public Calendar()
        {
            TitleLeftArrow = new CalendarButton
            {
                FontAttributes = FontAttributes.Bold,
                TintColor      = Color.Transparent,
                FontSize       = 24,
                Text           = "❰",
                TextColor      = Color.FromHex("#c82727")
            };
            TitleLabel = new Label
            {
                FontSize = 24,
                VerticalTextAlignment   = TextAlignment.Center,
                HorizontalTextAlignment = TextAlignment.Center,
                FontAttributes          = FontAttributes.Bold,
                TextColor         = Color.Black,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text = ""
            };
            TitleRightArrow = new CalendarButton
            {
                FontAttributes = FontAttributes.Bold,
                TintColor      = Color.Transparent,
                FontSize       = 24,
                Text           = "❱",
                TextColor      = Color.FromHex("#c82727")
            };
            MonthNavigationLayout = new StackLayout
            {
                Padding         = 0,
                VerticalOptions = LayoutOptions.Start,
                Orientation     = StackOrientation.Horizontal,
                HeightRequest   = Device.RuntimePlatform == Device.UWP ? 50 : 32,
                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;
        }
Beispiel #2
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;
            });
        }