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
Thank you so much for the code example - i try not to ask for code (but when it comes to Creation & Draw Filters I am at a bit of a loss.
Close by no cigar!
The hours appear to be be formatted correctly but the minutes are not appearing.
Here is my code converted to VB.NET (the interesting part anyways)
Dim hourElement As nsDayView.HourUIElement = TryCast(parent, nsDayView.HourUIElement) If hourElement IsNot Nothing Then Dim descriptorElement As nsDayView.TimeSlotDescriptorUIElement = TryCast(hourElement.GetAncestor(GetType(nsDayView.TimeSlotDescriptorUIElement)), nsDayView.TimeSlotDescriptorUIElement) Dim slot As TimeSlot = descriptorElement.FirstTimeSlot hourElement.Text = slot.StartTime.ToString(Me.format) End If Dim timeSlotDescriptorElement As nsDayView.TimeSlotDescriptorUIElement = TryCast(parent, nsDayView.TimeSlotDescriptorUIElement) If timeSlotDescriptorElement IsNot Nothing Then Dim minuteElement As nsDayView.MinuteUIElement = TryCast(timeSlotDescriptorElement.GetDescendant(GetType(nsDayView.MinuteUIElement)), nsDayView.MinuteUIElement) If minuteElement IsNot Nothing Then minuteElement.Text = "00" End If End If
What am I doing wrong to end up with the following image: (NOTE even though 1pm is not shown in the image I can assure you that the control now shows "13" which is almost there but I want "13:00" -- "13:15" -- "13:30" -- "13:45" -- "14:00")
Thanks In Advance
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
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?