public CodedMainPage(string date) { Title = "It-Conference"; events = new List <EventModel>(); var conference = JsonConvert.DeserializeObject <Conference>(App.Current.Properties["conference"].ToString()); foreach (var eventItem in conference.Events) { if (eventItem.Date.Equals(date)) { events.Add(eventItem); } } _schemaHandler = new SchemaHandler(); Grid calendarGrid = new Grid(); calendarGrid.Padding = 2; //Adds rows for (int i = 0; i < 26; i++) { RowDefinition rowDef = new RowDefinition(); rowDef.Height = 30; calendarGrid.RowDefinitions.Add(rowDef); } //Adds Columns calendarGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = 45 }); calendarGrid.ColumnDefinitions.Add(new ColumnDefinition()); calendarGrid.ColumnDefinitions.Add(new ColumnDefinition()); //Adds hours to the calendar int hours = 0; for (int i = 0; i < 49; i++) { if (i % 2 == 0) { StackLayout stackLay = new StackLayout { Children = { new Label { Text = hours + ":00", HeightRequest = 30, FontSize = 10, BackgroundColor = Color.White, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }, }, BackgroundColor = Color.Black, Padding = 1, HorizontalOptions = LayoutOptions.FillAndExpand, }; calendarGrid.Children.Add(stackLay, 0, i + 1); } else { calendarGrid.Children.Add(new StackLayout { Children = { new Label { Text = hours + ":30", HeightRequest = 30, FontSize = 10, BackgroundColor = Color.White, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }, }, BackgroundColor = Color.Black, Padding = 1, HorizontalOptions = LayoutOptions.FillAndExpand }, 0, i + 1); hours++; } } //Adds Column headers calendarGrid.Children.Add(new StackLayout { Children = { new Label { Text = "Track 1", FontSize = 20, FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Center } }, }, 1, 0); calendarGrid.Children.Add(new StackLayout { Children = { new Label { Text = "Track 2", FontSize = 20, FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Center } }, }, 2, 0); //Count For Event Color int count = 0; int count2 = 0; //Add events to calendar. foreach (var item in events) { if (item.Track.Equals("track1")) { count++; calendarGrid.Children.Add(new StackLayout { Orientation = StackOrientation.Horizontal, BackgroundColor = _schemaHandler.CalendarColorManager(count), Children = { new Label { FontSize = 10, Text = _schemaHandler.TruncateTitle(item.Name) + "\n" + item.StartTime + "\n -\n" + item.StopTime }, new Image { Source = "icon.png", HeightRequest = 20, WidthRequest = 20, HorizontalOptions = LayoutOptions.EndAndExpand, VerticalOptions = LayoutOptions.Start } }, GestureRecognizers = { new TapGestureRecognizer { Command = new Command(() => App.masterDetailPage.Detail = new NavigationPage(new EventDetailPage(item, false)) { BarBackgroundColor = Color.Green }), } }, }, 1, 2, _schemaHandler.ConvertStartTimeToRows(item.StartTime), _schemaHandler.ConvertStartTimeToRows(item.StartTime) + _schemaHandler.ConvertStopTimeToRows(item.StopTime, item.StartTime)); } else { count2++; calendarGrid.Children.Add(new StackLayout { Orientation = StackOrientation.Horizontal, BackgroundColor = _schemaHandler.CalendarColorManager2(count2), Children = { new Label { FontSize = 10, Text = _schemaHandler.TruncateTitle(item.Name) + "\n" + item.StartTime + "\n -\n" + item.StopTime }, new Image { Source = "icon.png", HeightRequest = 20, WidthRequest = 20, HorizontalOptions = LayoutOptions.EndAndExpand, VerticalOptions = LayoutOptions.Start } }, GestureRecognizers = { new TapGestureRecognizer { Command = new Command(() => App.masterDetailPage.Detail = new NavigationPage(new EventDetailPage(item, false)) { BarBackgroundColor = Color.Green }), } }, }, 2, 3, _schemaHandler.ConvertStartTimeToRows(item.StartTime), _schemaHandler.ConvertStartTimeToRows(item.StartTime) + _schemaHandler.ConvertStopTimeToRows(item.StopTime, item.StartTime)); } } Content = new ScrollView { Content = calendarGrid, }; //Save this bit of code to show different visual possibillities. //eventItems = new ObservableCollection<EventViewModel>(); //ListView listView = new ListView(); //listView.RowHeight = 100; //listView.ItemTemplate = new DataTemplate(typeof(CustomEventCell)); //eventItems.Add(new EventViewModel { Name = "BestEvent", StartTime = "18:00", StopTime = "19:00", Image = "icon.png", Description = "blablablablablablablablablablablablablablablablablablablablablablablablablablablablablabla..."}); //eventItems.Add(new EventViewModel { Name = "BestEvent", StartTime = "18:00", StopTime = "19:00", Image = "icon.png", Description = "blablabla..." }); //eventItems.Add(new EventViewModel { Name = "BestEvent", StartTime = "18:00", StopTime = "19:00", Image = "icon.png", Description = "blablabla..." }); //eventItems.Add(new EventViewModel { Name = "BestEvent", StartTime = "18:00", StopTime = "19:00", Image = "icon.png", Description = "blablabla..." }); //eventItems.Add(new EventViewModel { Name = "BestEvent", StartTime = "18:00", StopTime = "19:00", Image = "icon.png", Description = "blablabla..." }); //eventItems.Add(new EventViewModel { Name = "BestEvent", StartTime = "18:00", StopTime = "19:00", Image = "icon.png", Description = "blablabla..." }); //eventItems.Add(new EventViewModel { Name = "BestEvent", StartTime = "18:00", StopTime = "19:00", Image = "icon.png", Description = "blablabla..." }); //eventItems.Add(new EventViewModel { Name = "BestEvent", StartTime = "18:00", StopTime = "19:00", Image = "icon.png", Description = "blablabla..." }); //eventItems.Add(new EventViewModel { Name = "BestEvent", StartTime = "18:00", StopTime = "19:00", Image = "icon.png", Description = "blablabla..." }); //eventItems.Add(new EventViewModel { Name = "BestEvent", StartTime = "18:00", StopTime = "19:00", Image = "icon.png", Description = "blablabla..." }); //eventItems.Add(new EventViewModel { Name = "BestEvent", StartTime = "18:00", StopTime = "19:00", Image = "icon.png", Description = "blablabla..." }); //eventItems.Add(new EventViewModel { Name = "BestEvent", StartTime = "18:00", StopTime = "19:00", Image = "icon.png", Description = "blablabla..." }); //eventItems.Add(new EventViewModel { Name = "BestEvent", StartTime = "18:00", StopTime = "19:00", Image = "icon.png", Description = "blablabla..." }); //eventItems.Add(new EventViewModel { Name = "BestEvent", StartTime = "18:00", StopTime = "19:00", Image = "icon.png", Description = "blablabla..." }); //listView.ItemsSource = eventItems; //listView.ItemTapped += async (sender, e) => //{ // var eventItem = e.Item as EventViewModel; // await Navigation.PushModalAsync(new NavigationPage(new EventDetailPage(eventItem))); //}; //Content = listView; }
public PersonalSchema(string date) { Title = "Personal Schema"; schemaHandler = new SchemaHandler(); Grid calendarGrid = new Grid(); calendarGrid.Padding = 2; //Adds rows for (int i = 0; i < 26; i++) { RowDefinition rowDef = new RowDefinition(); rowDef.Height = 30; calendarGrid.RowDefinitions.Add(rowDef); } //Adds Columns calendarGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = 45 }); calendarGrid.ColumnDefinitions.Add(new ColumnDefinition()); calendarGrid.ColumnDefinitions.Add(new ColumnDefinition()); //Adds hours to the calendar int hours = 0; for (int i = 0; i < 49; i++) { if (i % 2 == 0) { StackLayout stackLay = new StackLayout { Children = { new Label { Text = hours + ":00", HeightRequest = 30, FontSize = 10, BackgroundColor = Color.White, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }, }, BackgroundColor = Color.Black, Padding = 1, HorizontalOptions = LayoutOptions.FillAndExpand, }; calendarGrid.Children.Add(stackLay, 0, i + 1); } else { calendarGrid.Children.Add(new StackLayout { Children = { new Label { Text = hours + ":30", HeightRequest = 30, FontSize = 10, BackgroundColor = Color.White, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }, }, BackgroundColor = Color.Black, Padding = 1, HorizontalOptions = LayoutOptions.FillAndExpand }, 0, i + 1); hours++; } } //Adds Column headers calendarGrid.Children.Add(new StackLayout { Children = { new Label { Text = "Track 1", FontSize = 20, FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Center } }, }, 1, 0); calendarGrid.Children.Add(new StackLayout { Children = { new Label { Text = "Track 2", FontSize = 20, FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Center } }, }, 2, 0); List <EventModel> eventList = new List <EventModel>(); if (Application.Current.Properties.ContainsKey("personalSchema")) { foreach (var eventItem in JsonConvert.DeserializeObject <List <EventModel> >(Application.Current.Properties["personalSchema"].ToString())) { if (eventItem.Date.Equals(date)) { eventList.Add(eventItem); } } //Count For Event Color int count = 0; int count2 = 0; //Add events to calendar. foreach (var item in eventList) { if (item.Track.Equals("track1")) { count++; calendarGrid.Children.Add(new StackLayout { Orientation = StackOrientation.Horizontal, BackgroundColor = schemaHandler.CalendarColorManager(count), Children = { new Label { FontSize = 10, Text = schemaHandler.TruncateTitle(item.Name) + "\n" + item.StartTime + "\n -\n" + item.StopTime }, new Image { Source = "icon.png", HeightRequest = 20, WidthRequest = 20, HorizontalOptions = LayoutOptions.EndAndExpand, VerticalOptions = LayoutOptions.Start } }, GestureRecognizers = { new TapGestureRecognizer { Command = new Command(() => App.masterDetailPage.Detail = new NavigationPage(new EventDetailPage(item, true)) { BarBackgroundColor = Color.Green }), } }, }, 1, 2, schemaHandler.ConvertStartTimeToRows(item.StartTime), schemaHandler.ConvertStartTimeToRows(item.StartTime) + schemaHandler.ConvertStopTimeToRows(item.StopTime, item.StartTime)); } else { count2++; calendarGrid.Children.Add(new StackLayout { Orientation = StackOrientation.Horizontal, BackgroundColor = schemaHandler.CalendarColorManager2(count2), Children = { new Label { FontSize = 10, Text = schemaHandler.TruncateTitle(item.Name) + "\n" + item.StartTime + "\n -\n" + item.StopTime }, new Image { Source = "icon.png", HeightRequest = 20, WidthRequest = 20, HorizontalOptions = LayoutOptions.EndAndExpand, VerticalOptions = LayoutOptions.Start } }, GestureRecognizers = { new TapGestureRecognizer { Command = new Command(() => App.masterDetailPage.Detail = new NavigationPage(new EventDetailPage(item, true)) { BarBackgroundColor = Color.Green }), } }, }, 2, 3, schemaHandler.ConvertStartTimeToRows(item.StartTime), schemaHandler.ConvertStartTimeToRows(item.StartTime) + schemaHandler.ConvertStopTimeToRows(item.StopTime, item.StartTime)); } } } else { DisplayAlert("", "You haven't added any events yet, go to main page and tab an event to add it to your personal schema", "Ok"); } Content = new ScrollView { Content = calendarGrid, }; }