Hi
Our application contains an UltraWeekView on which we show tasks. Admittedly it is still a version 5.3 control, which is unlikely to be changed.
I have a request to be able to show the year alongside the date at the top of each day box. The date is currently being shown in the format "Thursday 28 May"
Is this possible using the built in functionality or am I going to have to go down the route of implementing IUIElementDrawFilter?
Thanks
Tom
I like to use the IUIElementCreationFilter interface (as opposed to IUIElementDrawFilter) where possible sonce you are then less likely to have to reinvent any of the drawing code. The following example demonstrates how to solve the problem you describe here using that approach:
using nsWeekView = Infragistics.Win.UltraWinSchedule.WeekView;
this.ultraWeekView1.CreationFilter = new HeaderLongDateCreationFilter();
#region HeaderLongDateCreationFilterpublic class HeaderLongDateCreationFilter : IUIElementCreationFilter{
#region IUIElementCreationFilter Members
void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { nsWeekView.DayNumberUIElement headerElement = parent as nsWeekView.DayNumberUIElement;
if ( headerElement != null ) { List<TextUIElement> textElements = new List<TextUIElement>(); foreach(UIElement element in parent.ChildElements) { if ( element is TextUIElement ) textElements.Add( element as TextUIElement ); }
if ( textElements.Count == 2 ) parent.ChildElements.Remove( textElements[1] );
TextUIElement textElement = headerElement.GetDescendant( typeof(TextUIElement) ) as TextUIElement; if ( textElement != null ) { object dateContext = headerElement.GetContext( typeof(DateTime) ); if ( dateContext != null && dateContext is DateTime ) { DateTime date = (DateTime)dateContext; string dateText = date.ToLongDateString(); textElement.Text = dateText; textElement.Rect = parent.RectInsideBorders; } } } }
bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { return false; }
#endregion}#endregion HeaderLongDateCreationFilter
Thanks for the code sample. Pointing me in the direction of IUIElementCreationFilter was the key - it turns out that someone here has already implemented IUIElementCreationFilter, probably years ago.
Their implementation (with my modification for year display), is as follows. I am posting it because it's a bit more concise than your sample. Can you see any disadvantages that I've missed in my implementation?
public void AfterCreateChildElements(Infragistics.Win.UIElement parent) { // Change the format of the date label on the week view. if (parent is Infragistics.Win.TextUIElement && (parent.Parent is Infragistics.Win.UltraWinSchedule.WeekView.DayNumberUIElement || parent.Parent is Infragistics.Win.UltraWinSchedule.WeekView.CurrentDayNumberSelectionAreaUIElement)) { Infragistics.Win.TextUIElement textElement = parent as Infragistics.Win.TextUIElement;
Infragistics.Win.UltraWinSchedule.Day day = parent.SelectableItem as Infragistics.Win.UltraWinSchedule.Day;
textElement.Text = string.Format( "{0} {1} {2}", day.Date.DayOfWeek.ToString(), textElement.Text, day.Date.Year); } }