Пример #1
0
        public FluentInitializer WithSelectedDates(ICollection <DateTime> selectedDates)
        {
            if (_calendar.Mode == CalendarPickerView.SelectionMode.Single && _calendar.SelectedDates.Count > 1)
            {
                throw new IllegalArgumentException("SINGLE mode can't be used with multiple selectedDates");
            }
            if (_calendar.SelectedDates != null)
            {
                foreach (var date in selectedDates)
                {
                    _calendar.SelectDate(date);
                }
            }
            int selectedIndex = -1;
            int todayIndex    = -1;

            for (int i = 0; i < _calendar.Months.Count; i++)
            {
                var month = _calendar.Months[i];
                if (selectedIndex == -1)
                {
                    if (_calendar.SelectedCals.Any(
                            selectedCal => CalendarPickerView.IsSameMonth(selectedCal, month)))
                    {
                        selectedIndex = i;
                    }
                    if (selectedIndex == -1 && todayIndex == -1 &&
                        CalendarPickerView.IsSameMonth(DateTime.Now, month))
                    {
                        todayIndex = i;
                    }
                }
            }
            if (selectedIndex != -1)
            {
                _calendar.ScrollToSelectedMonth(selectedIndex);
            }
            else if (todayIndex != -1)
            {
                _calendar.ScrollToSelectedMonth(todayIndex);
            }

            _calendar.ValidateAndUpdate();
            return(this);
        }