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
The example I posted used a format of "HH"; it is possible you just have to change that to "HH:mm". It looks by the screen shot like you are using a TimeSlotInterval of 'TenMinutes', but I am at a loss as to how you got the text to appear for each slot (by default, it only appears for the first slot in the hour section). If you could illuminate on that point we can try to help.
No trick to it:
Me.dayViewAppointments.TimeSlotDescriptorLabelStyle = TimeSlotDescriptorLabelStyle.EveryTimeSlot
CheersAaron
Any news brian?
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
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(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
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.
// 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.