Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
180
Various SelectedDayAppearance
posted

Hi Infragistics,

 

I am struggling a bit with the UltraMonthViewMulti and SelectedDayAppearance. I need working days and non-working days to appear different. For that, I am setting up non-working days appearance by 'CalendarLook.GetDayLook(date, True).Appearance.xxx', and working days by 'CalendarLook.DayAppearance.xxx'.

However, I want the non-working days also to appear different than working days when they are selected, but I am unable to find the correct method to do that. Please note, that both working days and non-working days can be selected at the same time. so simply change the 'CalendarLook.SelectedDayAppearance.xxx' won't do the trick.

 

Thanks in advance,

Thomas

  • 69832
    Offline posted

    The following code sample demonstrates how to change a date's appearance dynamically as the selection changes, based on whether that date is a working day: 

    using Infragistics.Win;
    using Infragistics.Win.UltraWinSchedule;

    Infragistics.Win.Appearance workingDaySelectedAppearance = new Infragistics.Win.Appearance();
    Infragistics.Win.Appearance nonWorkingDaySelectedAppearance = new Infragistics.Win.Appearance();

    //  Set the properties on the working day and non-working day appearances
    this.workingDaySelectedAppearance.BackColor = Color.Green;
    this.nonWorkingDaySelectedAppearance.BackColor = Color.LightBlue;

    //  Set the UltraCalendarInfo's Tag property to reference the
    //  UltraCalendarLook, so we can get that reference easily
    //  in the BeforeSelectedDateRangeChange event
    this.ultraMonthViewMulti1.CalendarInfo.Tag = this.ultraMonthViewMulti1.CalendarLook;

    //  Handle the BeforeSelectedDateRangeChange event
    this.ultraMonthViewMulti1.CalendarInfo.BeforeSelectedDateRangeChange += new BeforeSelectedDateRangeChangeEventHandler(CalendarInfo_BeforeSelectedDateRangeChange);

    void CalendarInfo_BeforeSelectedDateRangeChange(object sender, BeforeSelectedDateRangeChangeEventArgs e)
    {
        //  Get the UltraCalendarInfo and UltraCalendarLook
        UltraCalendarInfo calendarInfo = sender as UltraCalendarInfo;
        UltraCalendarLook calendarLook = calendarInfo.Tag as UltraCalendarLook;

        //  First clear the ones that were set on the last selection
        this.ApplySelectedAppearance( calendarInfo, calendarLook, calendarInfo.SelectedDateRanges, null, null );

        //  Now set the appearance for the new selection
        this.ApplySelectedAppearance( calendarInfo, calendarLook, e.NewSelectedDateRanges, this.workingDaySelectedAppearance, this.nonWorkingDaySelectedAppearance );
    }

    private void ApplySelectedAppearance(
        UltraCalendarInfo calendarInfo,
        UltraCalendarLook calendarLook,
        SelectedDateRanges selectedDateRanges,
        Infragistics.Win.Appearance workingDaySelectedAppearance,
        Infragistics.Win.Appearance nonWorkingDaySelectedAppearance )
    {
        //  Create a dictionary that holds the selected dates and their
        //  respective DayLook objects
        Dictionary<DateTime, DayLook> dayLookList = new Dictionary<DateTime, DayLook>(selectedDateRanges.SelectedDaysCount);

        //  Iterate the date ranges
        foreach( DateRange range in selectedDateRanges )
        {
            //  Iterate each date in the current range, and add the DayLook
            //  for that date to the dictionary
            DateTime date = range.StartDate;
            while ( date <= range.EndDate )
            {
                dayLookList.Add( date, calendarLook.GetDayLook( date, true ) );
                date = date.AddDays(1);
            }

            //  Iterate the dictionary entries and apply the appropriate appearance
            foreach( KeyValuePair<DateTime, DayLook> item in dayLookList )
            {
                bool isWorkDay = calendarInfo.DaysOfWeek[item.Key.DayOfWeek].IsWorkDay;

                Infragistics.Win.Appearance appearance = isWorkDay ?
                    workingDaySelectedAppearance :
                    nonWorkingDaySelectedAppearance;

                item.Value.Appearance = appearance;
            }
        }

    }