private void DayBox_DragEnter(object sender, DragEventArgs e) { if (e.Source.GetType() == typeof(DayBoxControl) && Utilities.FindVisualAncestor(typeof(DayBoxAppointmentControl), e.OriginalSource as Visual) == null) { DayBoxControl dbc = (DayBoxControl)e.Source; dbc.Highlight(); } }
private void BuildCalendarUI() { int iDaysInMonth = sysCal.GetDaysInMonth(_DisplayStartDate.Year, _DisplayStartDate.Month); int iOffsetDays = System.Convert.ToInt32(System.Enum.ToObject(typeof(System.DayOfWeek), _DisplayStartDate.DayOfWeek)); int iWeekCount = 0; WeekOfDaysControls weekRowCtrl = new WeekOfDaysControls(); MonthViewGrid.Children.Clear(); AddRowsToMonthGrid(iDaysInMonth, iOffsetDays); MonthYearLabel.Content = months.ElementAt(_DisplayMonth - 1) + " " + _DisplayYear; for (int i = 1; i <= iDaysInMonth; i++) { if ((i != 1) && System.Math.IEEERemainder((i + iOffsetDays - 1), 7) == 0) { // -- add existing weekrowcontrol to the monthgrid Grid.SetRow(weekRowCtrl, iWeekCount); MonthViewGrid.Children.Add(weekRowCtrl); // -- make a new weekrowcontrol weekRowCtrl = new WeekOfDaysControls(); iWeekCount += 1; } // -- load each weekrow with a DayBoxControl whose label is set to day number DayBoxControl dayBox = new DayBoxControl(i); dayBox.DayNumberLabel.Content = i.ToString(); dayBox.Tag = i; dayBox.MouseDoubleClick += DayBox_DoubleClick; dayBox.DragEnter += DayBox_DragEnter; // -- customize daybox for today: if ((new DateTime(_DisplayYear, _DisplayMonth, i)) == DateTime.Today) { dayBox.DayLabelRowBorder.Background = (Brush)dayBox.TryFindResource("OrangeGradientBrush"); dayBox.DayAppointmentsStack.Background = Brushes.Wheat; } if (_monthAppointments != null) { int iday = i; Predicate <Vacation> aptFind = delegate(Vacation apt) { return((int)apt.m_curDate.Day == iday); }; List <Vacation> aptInDay = _monthAppointments.FindAll(aptFind); foreach (Vacation a in aptInDay) { DayBoxAppointmentControl apt = new DayBoxAppointmentControl(); apt.SetDoctor(a.m_doctor); apt.m_startDate = a.m_startDate; apt.m_endDate = a.m_endDate; apt.DisplayText.Text = a.m_doctor + " vacation until: " + a.m_endDate.ToString("d"); apt.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); apt.MouseDoubleClick += Appointment_DoubleClick; dayBox.DayAppointmentsStack.Children.Add(apt); } } Grid.SetColumn(dayBox, (i - (iWeekCount * 7)) + iOffsetDays); weekRowCtrl.WeekRowGrid.Children.Add(dayBox); } Grid.SetRow(weekRowCtrl, iWeekCount); MonthViewGrid.Children.Add(weekRowCtrl); }