Exemplo n.º 1
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 (var r = 0; r < 4; r++)
            {
                for (var 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;
        });
Exemplo n.º 2
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;
        }