private void GenerateSlots(int timeSlotsCount) { var source = this.AppointmentItemsControl.ItemsSource as AppointmentSlotCollection; for (int i = 0; i < timeSlotsCount; i++) { TimeSlotItem item = this.TimeSlotItemsControl.ItemContainerGenerator.ContainerFromIndex(i) as TimeSlotItem; if (item != null) { this.slots.Add(new TimeSlotItemAppointments(item)); } } foreach (var item in this.slots) { TimeSlotItem timeSlotItem = item.TimeSlotItem; TimeSlot timeSlot = item.TimeSlot; var appointmentSlots = (from appointmentSlot in source where appointmentSlot.TimeSlot.Start == timeSlot.Start orderby appointmentSlot.Occurrence.Duration() descending select appointmentSlot).ToList(); int index = 0; bool indexInUse = item.Appointments.ContainsKey(index); while (indexInUse) { index++; indexInUse = item.Appointments.ContainsKey(index); } foreach (var appSlot in appointmentSlots) { int durationInDays = this.GetAppointmentSlotDuration(appSlot); item.Appointments[index] = appSlot; if (durationInDays > 1) { int timeSlotIndex = this.slots.IndexOf(item) + 1; int count = Math.Min(durationInDays + timeSlotIndex - 1, this.slots.Count); for (int i = timeSlotIndex; i < count; i++) { TimeSlotItemAppointments nextTimeSlotAppointment = this.slots[i]; nextTimeSlotAppointment.Appointments[index] = appSlot; } } index++; indexInUse = item.Appointments.ContainsKey(index); while (indexInUse) { index++; indexInUse = item.Appointments.ContainsKey(index); } } } }
private void GenerateContainers(TimeSlotItemAppointments timeSlotAppointment, AppointmentSlotCollection source) { var timeSlotItem = timeSlotAppointment.TimeSlotItem; var timeSlot = timeSlotItem.TimeSlot; var contentHost = timeSlotItem.ContentHost ?? timeSlotItem; double contentHostHeight = contentHost.RenderSize.Height; int childIndex = 0; double stackDesiredSizeHeight = 0; IItemContainerGenerator generator = this.ItemContainerGenerator; bool generate = true; for (int i = 0; i < timeSlotAppointment.Appointments.Count; i++) { if (!timeSlotAppointment.Appointments.ContainsKey(i)) { continue; } var appSlot = timeSlotAppointment.Appointments[i]; if (appSlot.TimeSlot.Start != timeSlot.Start) { continue; } int itemIndex = source.IndexOf(appSlot); UIElement child = ((System.Windows.Controls.ItemContainerGenerator)generator).ContainerFromIndex(itemIndex) as UIElement; if (!generate) { if (child != null) { this.RecycleAppointmentItem(child, itemIndex); } continue; } if (child == null) { GeneratorPosition position = generator.GeneratorPositionFromIndex(itemIndex); child = this.GenerateContainerAtPosition(position, ref childIndex); } Rect arrangeRect = this.GetLayoutSlot(appSlot); if (child != null) { child.Measure(arrangeRect.Size); Size desiredSize = child.DesiredSize; int currentIndex = i + 1; stackDesiredSizeHeight = desiredSize.Height * currentIndex; if (this.IsVirtualizing && stackDesiredSizeHeight >= contentHostHeight) { var button = timeSlotItem.ShowMoreButton; if (button != null) { button.Opacity = 1; button.IsEnabled = true; } this.RecycleAppointmentItem(child, itemIndex); generate = false; } } } }
/// <summary> /// Provides the behavior for the Measure pass of Silverlight layout. Classes can override this method to define their own Measure pass behavior. /// </summary> /// <param name="availableSize">The available size that this object can give to child objects. Infinity can be specified as a value to indicate that the object will size to whatever content is available.</param> /// <returns> /// The size that this object determines it needs during layout, based on its calculations of child object allotted sizes. /// </returns> protected override Size MeasureOverride(Size availableSize) { // This is need for WPF to initialize ItemConteinerGenerator property. if (this.InternalChildren != null) { } int timeSlotsCount; bool isHorizontal = this.Orientation == Orientation.Horizontal; AppointmentItemsControl appointmentsItemsControl = this.AppointmentItemsControl; Size timeSlotSize = this.GetTimeSlotItemContentHostRenderSize(out timeSlotsCount); if (timeSlotSize.IsEmpty || timeSlotSize == new Size() || (this.previousAvailableSize != availableSize && !isHorizontal)) { this.previousAvailableSize = availableSize; if (timeSlotsCount > 0) { this.containersGenerated = false; } if (!isHorizontal) { this.RecycleAllAppointmentItems(); } return(base.MeasureOverride(availableSize)); } else { this.previousAvailableSize = availableSize; if (isHorizontal) { if (this.columns.Count == 0) { this.InitializeColumns(); } this.GenerateContainers(); } else { RadScheduler scheduler = this.AppointmentItemsControl != null ? this.AppointmentItemsControl.Scheduler : null; if (scheduler != null && scheduler.ActiveViewDefinition != null && scheduler.ActiveViewDefinition.TimeSlotLength != TimeSpan.Zero) { this.timeSlotTimeSpan = scheduler.ActiveViewDefinition.TimeSlotLength; } else { this.timeSlotTimeSpan = singleDayTimeSpan; } if (this.slots.Count == 0) { this.GenerateSlots(timeSlotsCount); } if (this.IsVirtualizing && this.InRecyclingMode) { this.HideShowMoreButtons(); } var source = this.AppointmentItemsControl.ItemsSource as AppointmentSlotCollection; for (int i = 0; i < timeSlotsCount; i++) { TimeSlotItemAppointments item = this.slots[i] as TimeSlotItemAppointments; this.GenerateContainers(item, source); } } if (double.IsInfinity(availableSize.Width) || double.IsInfinity(availableSize.Height)) { return(this.TimeSlotItemsControl.DesiredSize); } return(availableSize); } }