internal void CalendarEventClicked(CalendarEventView eventToSelect) { foreach (CalendarDay day in DaysInCurrentMonth) { foreach (CalendarEventView e in day.Events.Children) { if (e.DataContext == eventToSelect.DataContext) { e.BackgroundColor = HighlightColor; } else { e.BackgroundColor = e.DefaultBackfoundColor; } } } }
internal void CalendarEventClicked(CalendarEventView eventToSelect) { foreach (CalendarDay day in DaysInCurrentMonth) { foreach (CalendarEventView e in day.Events.Items) { if (e.DataContext == eventToSelect.DataContext) { e.BackgroundColor = HighlightColor; if (e.EventTextBlock.IsVisible == true) { e.EventTextBlock.Visibility = Visibility.Collapsed; e.EventAmount.Visibility = Visibility.Visible; } else { e.EventAmount.Visibility = Visibility.Collapsed; e.EventTextBlock.Visibility = Visibility.Visible; } } else { e.BackgroundColor = e.DefaultBackfoundColor; if (e.EventTextBlock.IsVisible == true) { e.EventTextBlock.Visibility = Visibility.Collapsed; e.EventAmount.Visibility = Visibility.Visible; } else { e.EventAmount.Visibility = Visibility.Collapsed; e.EventTextBlock.Visibility = Visibility.Visible; } } } } }
private void DrawEvents() { // this method can be called when Events is not binded yet. So check that case and return if (Events == null) { return; } // when Events is binded, check if it is collection of ICalendarEvent (events must have DateFrom and DateTo) if (Events is IEnumerable <ICalendarEvent> events) { // add colors of events to array, to pick up them using number SolidColorBrush[] colors = { Color0, Color1, Color2 }; // index to array of colors int accentColor = 0; // loop all events foreach (var e in events.OrderBy(e => e.DateFrom)) { if (!e.DateFrom.HasValue || !e.DateTo.HasValue) { continue; } // number of row in day, in which event should be displayed int eventRow = 0; var dateFrom = (DateTime)e.DateFrom; var dateTo = (DateTime)e.DateTo; // loop all days of current event for (DateTime date = dateFrom; date <= dateTo; date = date.AddDays(1)) { // get DayOfWeek for current day of current event CalendarDay day = DaysInCurrentMonth.Where(d => d.Date.Date == date.Date).FirstOrDefault(); // day is in another mont, so skip it if (day == null) { continue; } // if the DayOfWeek is Monday, event shloud be displayed on first row if (day.Date.DayOfWeek == DayOfWeek.Monday) { eventRow = 0; } // but if there are some events before, event won't be on the first row, but after previous events if (day.Events.Children.Count > eventRow) { eventRow = Grid.GetRow(day.Events.Children[day.Events.Children.Count - 1]) + 1; } // get color for event int accentColorIndex = accentColor % colors.Count(); CalendarEventView calendarEventView = new CalendarEventView(colors[accentColorIndex], this); calendarEventView.DataContext = e; Grid.SetRow(calendarEventView, eventRow); day.Events.Children.Add(calendarEventView); } accentColor++; } } else { throw new ArgumentException("Events must be IEnumerable<ICalendarEvent>"); } }
public void CalendarEventDoubleClicked(CalendarEventView calendarEventView) { CalendarEventDoubleClickedEvent?.Invoke(this, calendarEventView); }