protected void SetButtonSpecial(CalendarButton button, SpecialDate special) { Device.BeginInvokeOnMainThread(() => { 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; } button.IsEnabled = special.Selectable; }); }
public Calendar() { TitleLeftArrow = new CalendarButton { FontAttributes = FontAttributes.Bold, BackgroundColor = 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, BackgroundColor = Color.Transparent, FontSize = 24, Text = "❱", TextColor = Color.FromHex("#c82727") }; MonthNavigationLayout = new StackLayout { Padding = 0, VerticalOptions = LayoutOptions.Start, Orientation = StackOrientation.Horizontal, HeightRequest = 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; }
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.CornerRadius = CornerRadius; button.FontFamily = button.IsOutOfMonth ? DatesFontFamilyOutsideMonth : DatesFontFamily; if (DatesAlternateBackgroundColor.HasValue && button.Row % 2 == 0) { button.BackgroundColor = button.IsOutOfMonth ? DatesBackgroundColorOutsideMonth : DatesAlternateBackgroundColor.Value; } else { button.BackgroundColor = button.IsOutOfMonth ? DatesBackgroundColorOutsideMonth : DatesBackgroundColor; } button.TextColor = button.IsOutOfMonth ? DatesTextColorOutsideMonth : DatesTextColor; button.FontAttributes = button.IsOutOfMonth ? DatesFontAttributesOutsideMonth : DatesFontAttributes; button.IsEnabled = ShowNumOfMonths == 1 || !button.IsOutOfMonth; }); }
protected void SetButtonSelected(CalendarButton button, bool isInsideMonth) { Device.BeginInvokeOnMainThread(() => { button.IsEnabled = true; button.IsSelected = true; button.FontSize = SelectedFontSize; button.BorderWidth = SelectedBorderWidth; button.BorderColor = SelectedBorderColor; button.BackgroundColor = SelectedBackgroundColor.HasValue ? SelectedBackgroundColor.Value : DatesBackgroundColor; button.TextColor = SelectedTextColor.HasValue ? SelectedTextColor.Value : (isInsideMonth ? DatesTextColor : DatesTextColorOutsideMonth); }); }
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); } }
protected void SetButtonDisabled(CalendarButton button) { Device.BeginInvokeOnMainThread(() => { button.FontSize = DisabledFontSize; button.BorderWidth = DisabledBorderWidth; button.BorderColor = DisabledBorderColor; button.BackgroundColor = DisabledBackgroundColor; button.TextColor = DisabledTextColor; button.IsEnabled = false; button.IsSelected = false; button.IsOutOfMonth = false; }); }
protected void SetButtonNormal(CalendarButton button, bool isInsideMonth) { Device.BeginInvokeOnMainThread(() => { button.IsEnabled = true; button.IsSelected = false; button.IsOutOfMonth = !isInsideMonth; button.FontSize = DatesFontSize; button.BorderWidth = BorderWidth; button.BorderColor = BorderColor; button.BackgroundColor = isInsideMonth ? DatesBackgroundColor : DatesBackgroundColorOutsideMonth; button.TextColor = isInsideMonth ? DatesTextColor : DatesTextColorOutsideMonth; }); }
protected void SetButtonNormal(CalendarButton button) { Device.BeginInvokeOnMainThread(() => { button.IsEnabled = true; button.IsSelected = false; button.BackgroundPattern = null; button.FontSize = DatesFontSize; button.BorderWidth = BorderWidth; button.BorderColor = BorderColor; button.BackgroundColor = button.IsOutOfMonth ? DatesBackgroundColorOutsideMonth : DatesBackgroundColor; button.TextColor = button.IsOutOfMonth ? DatesTextColorOutsideMonth : DatesTextColor; button.FontAttributes = button.IsOutOfMonth ? DatesFontAttributesOutsideMonth : DatesFontAttributes; button.IsEnabled = ShowNumOfMonths == 1 || !button.IsOutOfMonth; }); }
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; button.IsEnabled = false; button.IsSelected = false; }); }
protected void SetButtonSelected(CalendarButton button, SpecialDate special) { Device.BeginInvokeOnMainThread(() => { var defaultBackgroundColor = button.IsOutOfMonth ? DatesBackgroundColorOutsideMonth : DatesBackgroundColor; var defaultTextColor = button.IsOutOfMonth ? DatesTextColorOutsideMonth : DatesTextColor; var defaultFontAttributes = button.IsOutOfMonth ? DatesFontAttributesOutsideMonth : DatesFontAttributes; button.BackgroundPattern = special != null ? special.BackgroundPattern : null; button.IsEnabled = true; button.IsSelected = true; button.FontSize = SelectedFontSize; button.BorderWidth = SelectedBorderWidth; button.BorderColor = SelectedBorderColor; button.BackgroundColor = SelectedBackgroundColor.HasValue ? SelectedBackgroundColor.Value : (special != null && special.BackgroundColor.HasValue ? special.BackgroundColor.Value : defaultBackgroundColor); button.TextColor = SelectedTextColor.HasValue ? SelectedTextColor.Value : (special != null && special.TextColor.HasValue ? special.TextColor.Value : defaultTextColor); button.FontAttributes = SelectedFontAttributes != FontAttributes.None ? SelectedFontAttributes : (special != null && special.FontAttributes.HasValue ? special.FontAttributes.Value : defaultFontAttributes); }); }
protected void SetButtonSpecial(CalendarButton button, SpecialDate special) { if (button.IsOutOfMonth && HideSpecialOutOfMonth) { return; } 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; }); }
protected void SetButtonSelected(CalendarButton button, SpecialDate special) { Device.BeginInvokeOnMainThread(() => { button.BackgroundPattern = special != null ? special.BackgroundPattern : null; button.BackgroundImage = special != null ? special.BackgroundImage : 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.CornerRadius = SelectedCornerRadius ?? (special != null && special.CornerRadius.HasValue ? special.CornerRadius.Value : CornerRadius); 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); }); }
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 (int r = 0; r < YearsRow; r++) { for (int 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 = width; details.HeightRequest = height; ContentView.Children.Add(details); CalendarViewType = DateTypeEnum.Year; TitleLeftArrow.IsVisible = true; TitleRightArrow.IsVisible = true; Content = MainView; }); }