/// <summary> /// Отобразить года /// </summary> 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, ColumnDefinitions = new ColumnDefinitionCollection { columDef, columDef, columDef, columDef }, 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; }); }
public Calendar() { // Создаём кнопку в заголовке со стрелкой влево TitleLeftArrow = new CalendarButton { FontAttributes = FontAttributes.None, BackgroundColor = Color.Transparent, BackgroundImage = ImageSource.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 = ImageSource.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; }