void appointment_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (e.Source is DayBoxAppointmentControl) { DayBoxAppointmentControl d = e.Source as DayBoxAppointmentControl; Appointment a = (Appointment)d.DataContext; //MessageBox.Show("appointment:"+a.Subject); AppointmentEventArgs args = new AppointmentEventArgs(); args.Point = a; args.RoutedEvent = AppointmentDblClickedEvent; RaiseEvent(args); e.Handled = true; } }
private void BuildCalendarUI() { int iDaysInMonth = DateTime.DaysInMonth(DisplayStartDate.Year, DisplayStartDate.Month); //int iOffsetDays = System.Enum.ToObject(System.DayOfWeek, DisplayStartDate.DayOfWeek); int iOffsetDays = (int)DisplayStartDate.DayOfWeek; int iWeekCount = 0; WeekOfDaysControl weekRowCtrl = new WeekOfDaysControl(); MonthViewGrid.Children.Clear(); AddRowsToMonthGrid(iDaysInMonth, iOffsetDays); MonthYearLabel.Content = DisplayStartDate.ToString("MMMM") + " " + year; for (int i = 1; i <= iDaysInMonth; i++) { if ((i != 1) && System.Math.IEEERemainder((i + iOffsetDays - 1), 7) == 0) { Grid.SetRow(weekRowCtrl, iWeekCount); MonthViewGrid.Children.Add(weekRowCtrl); weekRowCtrl = new WeekOfDaysControl(); iWeekCount++; } DayBoxControl dayBox = new DayBoxControl(); dayBox.Name = "DayBox" + i; dayBox.DayNumberLabel.Text = i.ToString(); dayBox.Tag = i; dayBox.MouseDoubleClick += new MouseButtonEventHandler(dayBox_MouseDoubleClick); //dayBox.PreviewDragEnter += new DragEventHandler(dayBox_PreviewDragEnter); //dayBox.PreviewDragLeave += new DragEventHandler(dayBox_PreviewDragLeave); //rest the namescope of the daybox in case user drags appointment from this day to another day, then back again //UnregisterName("DayBox" + i.ToString()); //System.Windows.NameScope.SetNameScope(dayBox, new System.Windows.NameScope()); //RegisterName("DayBox" + i.ToString(), dayBox); //-- resets the list of control-names registered with this monthview (to avoid duplicates later) //UnregisterName("DayBox" + i.ToString()); //System.Windows.NameScope.SetNameScope(dayBox, new System.Windows.NameScope()); //RegisterName("DayBox" + i.ToString(), dayBox); if (appointments != null) { foreach (Appointment a in appointments) { if (a.ApDate.Day == i) { DayBoxAppointmentControl apt = new DayBoxAppointmentControl(); apt.Name = "Apt" + a.Id; apt.DataContext = a; apt.MouseDoubleClick += new MouseButtonEventHandler(appointment_MouseDoubleClick); dayBox.DayAppointmentsStack.Children.Add(apt); //dayBox.RegisterName(apt.Name, apt); } } } if (DateTime.Now.Day == i) { dayBox.DayLabelRowBorder.Background = Brushes.Aqua; dayBox.DayAppointmentsStack.Background = Brushes.Wheat; } Grid.SetColumn(dayBox, (i - (iWeekCount * 7)) + iOffsetDays); weekRowCtrl.WeekRowGrid.Children.Add(dayBox); } Grid.SetRow(weekRowCtrl, iWeekCount); MonthViewGrid.Children.Add(weekRowCtrl); }
private void BuildCalendarUI() { int iDaysInMonth = DateTime.DaysInMonth(DisplayStartDate.Year, DisplayStartDate.Month); //int iOffsetDays = System.Enum.ToObject(System.DayOfWeek, DisplayStartDate.DayOfWeek); int iOffsetDays = (int)DisplayStartDate.DayOfWeek; int iWeekCount = 0; WeekOfDaysControl weekRowCtrl = new WeekOfDaysControl(); MonthViewGrid.Children.Clear(); AddRowsToMonthGrid(iDaysInMonth, iOffsetDays); MonthYearLabel.Content = DisplayStartDate.ToString("MMMM") +" "+year; for (int i = 1; i <= iDaysInMonth; i++) { if ( (i != 1) && System.Math.IEEERemainder((i + iOffsetDays - 1), 7) == 0) { Grid.SetRow(weekRowCtrl, iWeekCount); MonthViewGrid.Children.Add(weekRowCtrl); weekRowCtrl = new WeekOfDaysControl(); iWeekCount++; } DayBoxControl dayBox = new DayBoxControl(); dayBox.Name = "DayBox" + i; dayBox.DayNumberLabel.Text = i.ToString(); dayBox.Tag = i; dayBox.MouseDoubleClick += new MouseButtonEventHandler(dayBox_MouseDoubleClick); //dayBox.PreviewDragEnter += new DragEventHandler(dayBox_PreviewDragEnter); //dayBox.PreviewDragLeave += new DragEventHandler(dayBox_PreviewDragLeave); //rest the namescope of the daybox in case user drags appointment from this day to another day, then back again //UnregisterName("DayBox" + i.ToString()); //System.Windows.NameScope.SetNameScope(dayBox, new System.Windows.NameScope()); //RegisterName("DayBox" + i.ToString(), dayBox); //-- resets the list of control-names registered with this monthview (to avoid duplicates later) //UnregisterName("DayBox" + i.ToString()); //System.Windows.NameScope.SetNameScope(dayBox, new System.Windows.NameScope()); //RegisterName("DayBox" + i.ToString(), dayBox); if(appointments != null) { foreach(Appointment a in appointments) { if (a.ApDate.Day == i) { DayBoxAppointmentControl apt = new DayBoxAppointmentControl(); apt.Name = "Apt" + a.Id; apt.DataContext = a; apt.MouseDoubleClick += new MouseButtonEventHandler(appointment_MouseDoubleClick); dayBox.DayAppointmentsStack.Children.Add(apt); //dayBox.RegisterName(apt.Name, apt); } } } if (DateTime.Now.Day == i) { dayBox.DayLabelRowBorder.Background = Brushes.Aqua; dayBox.DayAppointmentsStack.Background = Brushes.Wheat; } Grid.SetColumn(dayBox, (i - (iWeekCount * 7)) + iOffsetDays); weekRowCtrl.WeekRowGrid.Children.Add(dayBox); } Grid.SetRow(weekRowCtrl, iWeekCount); MonthViewGrid.Children.Add(weekRowCtrl); }