Represents a range of dates in a T:WinRTXamlToolkit.Controls.Calendar.
        /// <summary>
        /// Returns true if any day in the given DateTime range is contained in
        /// the current CalendarDateRange.
        /// </summary>
        /// <param name="range">Inherited code: Requires comment 1.</param>
        /// <returns>Inherited code: Requires comment 2.</returns>
        internal bool ContainsAny(CalendarDateRange range)
        {
            Debug.Assert(range != null, "range should not be null!");

            int start = DateTime.Compare(Start, range.Start);

            // Check if any part of the supplied range is contained by this
            // range or if the supplied range completely covers this range.
            return (start <= 0 && DateTime.Compare(End, range.Start) >= 0) ||
                (start >= 0 && DateTime.Compare(Start, range.End) <= 0);
        }
        /// <summary>
        /// Returns true if any day in the given DateTime range is contained in
        /// the current CalendarDateRange.
        /// </summary>
        /// <param name="range">Inherited code: Requires comment 1.</param>
        /// <returns>Inherited code: Requires comment 2.</returns>
        internal bool ContainsAny(CalendarDateRange range)
        {
            Debug.Assert(range != null, "range should not be null!");

            int start = DateTime.Compare(Start, range.Start);

            // Check if any part of the supplied range is contained by this
            // range or if the supplied range completely covers this range.
            return((start <= 0 && DateTime.Compare(End, range.Start) >= 0) ||
                   (start >= 0 && DateTime.Compare(Start, range.End) <= 0));
        }
Beispiel #3
0
        /// <summary>
        /// Returns if the date is included in the range.
        /// </summary>
        /// <param name="date">Inherited code: Requires comment 1.</param>
        /// <param name="range">Inherited code: Requires comment 2.</param>
        /// <returns>Inherited code: Requires comment 3.</returns>
        public static bool InRange(DateTime date, CalendarDateRange range)
        {
            Debug.Assert(DateTime.Compare(range.Start, range.End) < 1, "The range should start before it ends!");

            if (CompareDays(date, range.Start) > -1 && CompareDays(date, range.End) < 1)
            {
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Inherited code: Requires comment.
        /// </summary>
        /// <param name="shift">Inherited code: Requires comment 1.</param>
        /// <param name="lastSelectedDate">Inherited code: Requires comment 2.</param>
        /// <param name="index">Inherited code: Requires comment 3.</param>
        private void ProcessSelection(bool shift, DateTime? lastSelectedDate, int? index)
        {
            if (SelectionMode == CalendarSelectionMode.None && lastSelectedDate != null)
            {
                OnDayClick(lastSelectedDate.Value);
                return;
            }
            if (lastSelectedDate != null && IsValidKeyboardSelection(this, lastSelectedDate.Value))
            {
                if (SelectionMode == CalendarSelectionMode.SingleRange || SelectionMode == CalendarSelectionMode.MultipleRange)
                {
                    foreach (DateTime item in SelectedDates)
                    {
                        RemovedItems.Add(item);
                    }
                    SelectedDates.ClearInternal();
                    if (shift)
                    {
                        CalendarDayButton b;
                        _isShiftPressed = true;
                        if (HoverStart == null)
                        {
                            if (LastSelectedDate != null)
                            {
                                HoverStart = LastSelectedDate;
                            }
                            else
                            {
                                if (DateTimeHelper.CompareYearMonth(DisplayDateInternal, DateTime.Today) == 0)
                                {
                                    HoverStart = DateTime.Today;
                                }
                                else
                                {
                                    HoverStart = DisplayDateInternal;
                                }
                            }

                            b = FindDayButtonFromDay(HoverStart.Value);
                            if (b != null)
                            {
                                HoverStartIndex = b.Index;
                            }
                        }
                        // the index of the SelectedDate is always the last
                        // selectedDate's index
                        UnHighlightDays();
                        // If we hit a BlackOutDay with keyboard we do not
                        // update the HoverEnd
                        CalendarDateRange range;

                        if (DateTime.Compare(HoverStart.Value, lastSelectedDate.Value) < 0)
                        {
                            range = new CalendarDateRange(HoverStart.Value, lastSelectedDate.Value);
                        }
                        else
                        {
                            range = new CalendarDateRange(lastSelectedDate.Value, HoverStart.Value);
                        }

                        if (!BlackoutDates.ContainsAny(range))
                        {
                            HoverEnd = lastSelectedDate;

                            if (index.HasValue)
                            {
                                HoverEndIndex += index;
                            }
                            else
                            {
                                // For Home, End, PageUp and PageDown Keys there
                                // is no easy way to predict the index value
                                b = FindDayButtonFromDay(HoverEndInternal.Value);

                                if (b != null)
                                {
                                    HoverEndIndex = b.Index;
                                }
                            }
                        }

                        OnDayClick(HoverEnd.Value);
                        HighlightDays();
                    }
                    else
                    {
                        HoverStart = lastSelectedDate;
                        HoverEnd = lastSelectedDate;
                        AddSelection();
                        OnDayClick(lastSelectedDate.Value);
                    }
                }
                else
                {
                    // ON CLEAR 
                    LastSelectedDate = lastSelectedDate.Value;
                    if (SelectedDates.Count > 0)
                    {
                        SelectedDates[0] = lastSelectedDate.Value;
                    }
                    else
                    {
                        SelectedDates.Add(lastSelectedDate.Value);
                    }
                    OnDayClick(lastSelectedDate.Value);
                }
            }
        }
        /// <summary>
        /// Returns if the date is included in the range.
        /// </summary>
        /// <param name="date">Inherited code: Requires comment 1.</param>
        /// <param name="range">Inherited code: Requires comment 2.</param>
        /// <returns>Inherited code: Requires comment 3.</returns>
        public static bool InRange(DateTime date, CalendarDateRange range)
        {
            Debug.Assert(DateTime.Compare(range.Start, range.End) < 1, "The range should start before it ends!");

            if (CompareDays(date, range.Start) > -1 && CompareDays(date, range.End) < 1)
            {
                return true;
            }

            return false;
        }