private void loadCalendarGrid(PurseCalendarMonth monthData) { currentMonth = monthData; currentDateTime = new DateTime (monthData.year, monthData.month, 1); calendarGrid = new Grid { ColumnSpacing = 2, RowSpacing = 2, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }; for (int i = 1; i <= 7; i++) { calendarGrid.RowDefinitions.Add (new RowDefinition { Height = GridLength.Auto }); calendarGrid.ColumnDefinitions.Add (new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) }); } calendarGrid.Children.Add (new Label { Text = "Mon", TextColor = Color.Black, HorizontalTextAlignment = TextAlignment.Center }, 0, 0); calendarGrid.Children.Add (new Label { Text = "Tue", TextColor = Color.Black, HorizontalTextAlignment = TextAlignment.Center }, 1, 0); calendarGrid.Children.Add (new Label { Text = "Wed", TextColor = Color.Black, HorizontalTextAlignment = TextAlignment.Center }, 2, 0); calendarGrid.Children.Add (new Label { Text = "Thu", TextColor = Color.Black, HorizontalTextAlignment = TextAlignment.Center }, 3, 0); calendarGrid.Children.Add (new Label { Text = "Fri", TextColor = Color.Black, HorizontalTextAlignment = TextAlignment.Center }, 4, 0); calendarGrid.Children.Add (new Label { Text = "Sat", TextColor = Color.Black, HorizontalTextAlignment = TextAlignment.Center }, 5, 0); calendarGrid.Children.Add (new Label { Text = "Sun", TextColor = Color.Black, HorizontalTextAlignment = TextAlignment.Center }, 6, 0); int colPos = getDayOfWeek (currentDateTime); int rowCount = 1; foreach (KeyValuePair<int, List<SessionData>> k in monthData.monthData) { Label dayLabel = new Label (); if (k.Value.Count > 0) { dayLabel = new Label { Text = k.Value[0].sessionCode.code, TextColor = Color.Black, BackgroundColor = k.Value[0].sessionCode.sessionCodeColor }; } else { dayLabel = new Label { BackgroundColor = Color.Gray }; } calendarGrid.Children.Add (new StackLayout { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Children = { new Label { BackgroundColor = Color.Red, TextColor = Color.White, Text = k.Key.ToString() }, dayLabel } }, colPos, rowCount); colPos++; if (colPos > 6) { colPos = 0; rowCount++; } } }
public CalendarPage (PurseCalendarMonth monthData) { loadCalendarGrid (monthData); initialiseControls (); setContent (); }