Hi,
I have a requirement to display all the time slot descriptions in a 24 hour format. Eg. either "1:00 pm" or "13:00" would suffice. Is this possible?
If not directly, then I guess a creation filter is the way to go?
Thanks!
Ryan
Hi Brian,
This works fine for 24 hour format. But when system culture is 24 hour format and we want to show 12 hour format on calendar along with AM/ PM indicator while scrolling slider over calendar view. I have modified this code to show 12 format, but only problem is that it is not showing AM/ PM.
void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { nsDayView.HourUIElement hourElement = parent as nsDayView.HourUIElement; if ( hourElement != null ) { nsDayView.TimeSlotDescriptorUIElement descriptorElement = hourElement.GetAncestor( typeof(nsDayView.TimeSlotDescriptorUIElement) ) as nsDayView.TimeSlotDescriptorUIElement;
// TODO: this could be cached for better performance List<nsDayView.HourUIElement> hours = new List<Infragistics.Win.UltraWinSchedule.DayView.HourUIElement>(); foreach( UIElement element in descriptorElement.ChildElements ) { nsDayView.HourUIElement h = element as nsDayView.HourUIElement; if ( h != null ) hours.Add(h); }
// Get the number of slots in an hour int slotsPerHour = hours.Count;
// Get the index of this hour element int index = hours.IndexOf( hourElement );
// Get the number of minutes in a slot // (this should be the same as the value of the control's TimeSlotInterval) int minutesPerSlot = 60 / slotsPerHour;
// Multiply the index by the number of minutes in a slot int minute = minutesPerSlot * index;
// Offset the time of the first slot by the number of minutes TimeSlot slot = descriptorElement.FirstTimeSlot; DateTime startTime = slot.StartTime; startTime = startTime.AddMinutes( minute );
// Set the new text hourElement.Text = startTime.ToString("hh:mm"); }
Here, i don't want to use "hh:mm tt" format as it appends AM/ PM indicator to every time slot descriptor. The default calendar view shows AM/ PM to the 1st time slot of the calendar and I want exactly same behavior.
Thanks Brian... It worked perfectly (but ofcourse you knew that already :) )
One question though: In your code you made a comment that;
' TODO: this could be cached for better performance
What part of that code could be cached??? I assume by cached you mean I could extract something out to a Private Variable so that I didn't have to cast into it each time the code was hit?
I couldn't work out what could be optimised in the code example you showed.
You have to use a format of "HH:mm" to see the minutes.
This is revised code that accounts for the TimeSlotDescriptorLabelStyle setting you were using...note that this does not handle the other case, so I will leave it up to you to integrate the two solutions:
#region TimeSlotDecriptorCreationFilter/// <summary>/// Provides a way to add labels for DayView's TimeSlotUIElements/// </summary>public class TimeSlotDecriptorCreationFilter : IUIElementCreationFilter{ private string format = null; public TimeSlotDecriptorCreationFilter( string format ) { this.format = format; }
#region IUIElementCreationFilter interface implementation
// Set the new text hourElement.Text = startTime.ToString(this.format); }
nsDayView.TimeSlotDescriptorUIElement timeSlotDescriptorElement = parent as nsDayView.TimeSlotDescriptorUIElement; if ( timeSlotDescriptorElement != null ) { nsDayView.MinuteUIElement minuteElement = timeSlotDescriptorElement.GetDescendant( typeof(nsDayView.MinuteUIElement) ) as nsDayView.MinuteUIElement;
//if ( minuteElement != null ) // minuteElement.Text = "00"; }
}
bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { return false; }
#endregion IUIElementCreationFilter interface implementation
Any news brian?
No trick to it:
Me.dayViewAppointments.TimeSlotDescriptorLabelStyle = TimeSlotDescriptorLabelStyle.EveryTimeSlot
CheersAaron