コード例 #1
0
        private void SetYearButtons(DateTime decade, DateTime decadeEnd)
        {
            int decadeYear    = _calendar.GetYear(decade);
            int decadeEndYear = _calendar.GetYear(decadeEnd);
            int year;
            int count = -1;

            foreach (object child in _yearView.Children)
            {
                CalendarButton childButton = child as CalendarButton;
                Debug.Assert(childButton != null);
                year = decadeYear + count;

                if (year <= _calendar.MaxSupportedDateTime.Year && year >= _calendar.MinSupportedDateTime.Year)
                {
                    // There should be no time component. Time is 12:00 AM
                    DateTime day = _calendar.ToDateTime(year, 1, 1, 0, 0, 0, 0);
                    childButton.DataContext = day;
                    childButton.SetContentInternal(DateTimeHelper.ToYearString(day, DateTimeHelper.GetCulture(this)));
                    childButton.Visibility = Visibility.Visible;

                    if (Owner != null)
                    {
                        childButton.HasSelectedDays = (_calendar.GetYear(Owner.DisplayDate) == year);

                        if (year < Owner.DisplayDateStartInternal.Year || year > Owner.DisplayDateEndInternal.Year)
                        {
                            childButton.IsEnabled = false;
                            childButton.Opacity   = 0;
                        }
                        else
                        {
                            childButton.IsEnabled = true;
                            childButton.Opacity   = 1;
                        }
                    }

                    // SET IF THE YEAR IS INACTIVE OR NOT: set if the year is a trailing year or not
                    childButton.IsInactive = year <decadeYear || year> decadeEndYear;
                }
                else
                {
                    childButton.DataContext = null;
                    childButton.IsEnabled   = false;
                    childButton.Opacity     = 0;
                }

                count++;
            }
        }
コード例 #2
0
        private void SetYearModeMonthButtons()
        {
            int count = 0;

            foreach (object child in _yearView.Children)
            {
                CalendarButton childButton = child as CalendarButton;
                Debug.Assert(childButton != null);

                // There should be no time component. Time is 12:00 AM
                int      year  = _calendar.GetYear(DisplayDate);
                int      month = count + 1;
                DateTime day   = _calendar.ToDateTime(year, month, 1, 0, 0, 0, 0);
                childButton.DataContext = day;
                childButton.SetContentInternal(DateTimeHelper.ToAbbreviatedMonthString(day, DateTimeHelper.GetCulture(this)));
                childButton.Visibility = Visibility.Visible;

                if (Owner != null)
                {
                    Debug.Assert(Owner.DisplayDateInternal != null);
                    childButton.HasSelectedDays = (DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateInternal) == 0);

                    if (DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateStartInternal) < 0 || DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateEndInternal) > 0)
                    {
                        childButton.IsEnabled = false;
                        childButton.Opacity   = 0;
                    }
                    else
                    {
                        childButton.IsEnabled = true;
                        childButton.Opacity   = 1;
                    }
                }

                childButton.IsInactive = false;
                count++;
            }
        }