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); }
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 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; }); }
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; }); } }
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; }); }
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 Calendar() { TitleLeftArrow = new CalendarButton { FontAttributes = FontAttributes.None, BackgroundColor = Color.Transparent, HeightRequest = 28, WidthRequest = 28, Margin = new Thickness(24, 0, 0, 0), VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.End, TextColor = Color.FromHex("424242"), Text = "<" }; TitleLabel = new Label { FontSize = 24, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, FontAttributes = FontAttributes.None, TextColor = Color.FromHex("424242"), HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, Text = string.Empty, LineBreakMode = LineBreakMode.NoWrap }; TitleRightArrow = new CalendarButton { FontAttributes = FontAttributes.None, BackgroundColor = Color.Transparent, HeightRequest = 28, WidthRequest = 28, Margin = new Thickness(0, 0, 24, 0), VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Start, TextColor = Color.FromHex("424242"), Text = ">" }; MonthNavigationLayout = new StackLayout { Padding = 0, VerticalOptions = LayoutOptions.Start, Orientation = StackOrientation.Horizontal, HeightRequest = 30, 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; }
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 = 28, WidthRequest = 28, 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 = 28, WidthRequest = 28, 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 = 30, 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; }