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
Note that it uses the time format specified by the current culture, so in cases where the current culture's time format uses "H" as opposed to "h", you get this automatically.
If you want to force this regardless of the current culture settings, yes, you could use a creation filter. You can get the associated TimeSlot by using HourUIElement.GetAncestor(typeof(TimeSlotDescriptorUIElement)) to get the TimeSlotDescriptorUIElement, then accessing its FirstTimeSlot property.
Can you point me to an example of setting the TimeSlotDescriptor "time format" to 24 Hour time/Military Time
eg: 1:00 pm = 13:00
Cheers
Aaron
using Infragistics.Win;using Infragistics.Win.UltraWinSchedule;using nsDayView = Infragistics.Win.UltraWinSchedule.DayView;
this.dayView.CreationFilter = new TimeSlotDecriptorCreationFilter( "HH" );
#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
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;
TimeSlot slot = descriptorElement.FirstTimeSlot;
hourElement.Text = slot.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}#endregion TimeSlotDecriptorCreationFilter
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.
// 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:
// Set the new text hourElement.Text = startTime.ToString(this.format); }
//if ( minuteElement != null ) // minuteElement.Text = "00"; }
#endregion IUIElementCreationFilter interface implementation
Any news brian?
No trick to it:
Me.dayViewAppointments.TimeSlotDescriptorLabelStyle = TimeSlotDescriptorLabelStyle.EveryTimeSlot
CheersAaron