Hi,
I need to add an icon to the entries displayed in the calendar. I actually want to display the recurrence icon - I am implementing my own recurrence algorithm in SQL so don't use the inbuilt mechanism, however I want to show the recurrence icon in applicable entries.
I initially though I might be able to set a flag on the appointments to have them display the inbuilt icon, but without actually generating any recurrent entries, but the properties I was looking at are read only. :( So I am now thinking that I probably need to use a creation or draw filter, but I have no idea which elements I need to look for or modify, and I can't get the element viewer to work with my user control (hosted in a native app), so any help would be appreciated.
Thanks,
Brian
Hello Satoshi,
Thank you for contacting Infragistics Support.
In order to add an icon to an appointment you may set Image property of appointment appearance. You may use code like thid:
this.ultraCalendarInfo1.Appointments[i].Appearance.Image = image;
Please note this will add an image exactly where occurrence icon appears.
Please check attached sample solution and let me know if this is what you are looking for or if I am missing something.
Hi Milko,
Thanks for the quick response. I didn't realize that the image in Appearance was for the recurrence icon, and I have already used this to show a different icon for my various calendar item types, so I can't use it for the recurrence icon. I also thought that the recurrence icon would show on the right hand side, as it does in Outlook, so I have implemented a creation filter to add an image on the top right hand corner, it's not perfect as it will sit on top of the text if the item is too small, but it does work, and will probably do for now. When loading, I set the RecurrenceId property of the appointment to a GUID of zero if the item is not recurrent, all 1s if it is, and all 2s if it is recurrent and has been edited, than in the filter I display the appropriate icon, or none if it's not recurrent.
class AddIconFilter : IUIElementCreationFilter { #region IUIElementCreationFilter Members public void AfterCreateChildElements(UIElement parent) { Appointment appt = null; Size margin = new Size(); if (parent is Infragistics.Win.UltraWinSchedule.DayView.AppointmentUIElement) { Infragistics.Win.UltraWinSchedule.DayView.AppointmentUIElement elem = parent as Infragistics.Win.UltraWinSchedule.DayView.AppointmentUIElement; appt = elem.SelectableItem as Appointment; margin = new Size(8, 4); } else if (parent is Infragistics.Win.UltraWinSchedule.MonthViewSingle.AppointmentUIElement) { Infragistics.Win.UltraWinSchedule.MonthViewSingle.AppointmentUIElement elem = parent as Infragistics.Win.UltraWinSchedule.MonthViewSingle.AppointmentUIElement; appt = elem.SelectableItem as Appointment; margin = new Size(8, 0); } else if (parent is Infragistics.Win.UltraWinSchedule.TimelineView.AppointmentUIElement) { Infragistics.Win.UltraWinSchedule.TimelineView.AppointmentUIElement elem = parent as Infragistics.Win.UltraWinSchedule.TimelineView.AppointmentUIElement; appt = elem.SelectableItem as Appointment; margin = new Size(8, 0); } AddIconIfRequired(parent, appt, margin); } public bool BeforeCreateChildElements(UIElement parent) { return false; } #endregion #region Helpers void AddIconIfRequired(UIElement parent, Appointment appt, Size margin) { if (appt != null) { if (appt.RecurrenceId.CompareTo(FrmCalendar._recurrenceNoneGuid) != 0) { Image img = appt.RecurrenceId.CompareTo(FrmCalendar._recurrenceRootGuid) == 0 ? Properties.Resources.Recurring : Properties.Resources.RecurringEdit; ImageUIElement recurrenceIcon = new ImageUIElement(parent, img); Point ptIcon = new Point(Math.Max(parent.Rect.Right - img.Size.Width - margin.Width, 0), parent.Rect.Top + margin.Height); recurrenceIcon.Rect = new System.Drawing.Rectangle(ptIcon, new Size(16, 16)); parent.ChildElements.Add(recurrenceIcon); } } } #endregion }
It would be nice if it didn't overwrite the text, so I will probably look at trying to resize the text part to avoid this, and if you have any pointers for doing this that would be useful.