Пример #1
0
        private void Cell_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            CalendarDayButton b = sender as CalendarDayButton;

            if (b == null)
            {
                return;
            }

            if (Owner == null)
            {
                return;
            }

            if (!b.IsBlackedOut)
            {
                Owner.OnDayButtonMouseUp(e);
            }

            if (!(b.DataContext is DateTime))
            {
                return;
            }

            FinishSelection((DateTime)b.DataContext);
            e.Handled = true;
        }
Пример #2
0
        private void PopulateGrids()
        {
            if (_monthView != null)
            {
                if (_dayTitleTemplate != null)
                {
                    for (int i = 0; i < COLS; i++)
                    {
                        FrameworkElement titleCell = (FrameworkElement)this._dayTitleTemplate.LoadContent();
                        titleCell.SetValue(Grid.RowProperty, 0);
                        titleCell.SetValue(Grid.ColumnProperty, i);
                        this._monthView.Children.Add(titleCell);
                    }
                }

                for (int i = 1; i < ROWS; i++)
                {
                    for (int j = 0; j < COLS; j++)
                    {
                        CalendarDayButton dayCell = new CalendarDayButton();

                        dayCell.Owner = this.Owner;
                        dayCell.SetValue(Grid.RowProperty, i);
                        dayCell.SetValue(Grid.ColumnProperty, j);
                        dayCell.SetBinding(CalendarDayButton.StyleProperty, GetOwnerBinding("CalendarDayButtonStyle"));
                        dayCell.AddHandler(CalendarDayButton.MouseLeftButtonDownEvent, new MouseButtonEventHandler(Cell_MouseLeftButtonDown), true);
                        dayCell.AddHandler(CalendarDayButton.MouseLeftButtonUpEvent, new MouseButtonEventHandler(Cell_MouseLeftButtonUp), true);
                        dayCell.AddHandler(CalendarDayButton.MouseEnterEvent, new MouseEventHandler(Cell_MouseEnter), true);
                        dayCell.AddHandler(CalendarDayButton.MouseLeaveEvent, new MouseEventHandler(Cell_MouseLeave), true);
                        dayCell.Click += new RoutedEventHandler(Cell_Clicked);

                        this._monthView.Children.Add(dayCell);
                    }
                }
            }

            if (_yearView != null)
            {
                CalendarButton monthCell;
                int            count = 0;
                for (int i = 0; i < YEAR_ROWS; i++)
                {
                    for (int j = 0; j < YEAR_COLS; j++)
                    {
                        monthCell = new CalendarButton();

                        monthCell.Owner = this.Owner;
                        monthCell.SetValue(Grid.RowProperty, i);
                        monthCell.SetValue(Grid.ColumnProperty, j);
                        monthCell.SetBinding(CalendarButton.StyleProperty, GetOwnerBinding("CalendarButtonStyle"));
                        monthCell.AddHandler(CalendarButton.MouseLeftButtonDownEvent, new MouseButtonEventHandler(Month_MouseLeftButtonDown), true);
                        monthCell.AddHandler(CalendarButton.MouseLeftButtonUpEvent, new MouseButtonEventHandler(Month_MouseLeftButtonUp), true);
                        monthCell.AddHandler(CalendarButton.MouseEnterEvent, new MouseEventHandler(Month_MouseEnter), true);
                        monthCell.Click += new RoutedEventHandler(Month_Clicked);
                        this._yearView.Children.Add(monthCell);
                        count++;
                    }
                }
            }
        }
Пример #3
0
        private void EndDrag(bool ctrl, CalendarDayButton b)
        {
            if (this.Owner != null && b.DataContext is DateTime)
            {
                DateTime selectedDate = (DateTime)b.DataContext;
                this.Owner.CurrentDate = selectedDate;

                if (this.Owner.HoverStart.HasValue)
                {
                    if (
                        ctrl &&
                        DateTime.Compare(this.Owner.HoverStart.Value, selectedDate) == 0 &&
                        (Owner.SelectionMode == CalendarSelectionMode.SingleDate || Owner.SelectionMode == CalendarSelectionMode.MultipleRange))
                    {
                        // Ctrl + single click = toggle
                        this.Owner.SelectedDates.Toggle(selectedDate);
                    }
                    else
                    {
                        // this is selection with Mouse, we do not guarantee the range does not include BlackOutDates.
                        // Use the internal AddRange that omits BlackOutDates based on the SelectionMode
                        this.Owner.SelectedDates.AddRangeInternal(this.Owner.HoverStart.Value, selectedDate);
                    }

                    Owner.OnDayClick(selectedDate);
                }
            }
        }
Пример #4
0
        private void SetMonthModeCalendarDayButtons()
        {
            //DateTime firstDayOfMonth = DateTimeHelper.DiscardDayTime(DisplayDate);
            DateTime firstDayOfMonth    = DateTimeHelper.GetFirstDayOfMonth(DisplayDate);
            int      lastMonthToDisplay = GetNumberOfDisplayedDaysFromPreviousMonth(firstDayOfMonth);

            bool        isMinMonth  = DateTimeHelper.CompareYearMonth(firstDayOfMonth, _calendar.MinSupportedDateTime) <= 0;
            bool        isMaxMonth  = DateTimeHelper.CompareYearMonth(firstDayOfMonth, _calendar.MaxSupportedDateTime) >= 0;
            int         daysInMonth = _calendar.GetDaysInMonth(firstDayOfMonth.Year, firstDayOfMonth.Month);
            CultureInfo culture     = DateTimeHelper.GetCulture(this);

            int count = ROWS * COLS;

            for (int childIndex = COLS; childIndex < count; childIndex++)
            {
                CalendarDayButton childButton = _monthView.Children[childIndex] as CalendarDayButton;
                Debug.Assert(childButton != null);

                int dayOffset = childIndex - lastMonthToDisplay - COLS;
                if ((!isMinMonth || (dayOffset >= 0)) && (!isMaxMonth || (dayOffset < daysInMonth)))
                {
                    DateTime dateToAdd = _calendar.AddDays(firstDayOfMonth, dayOffset);
                    SetMonthModeDayButtonState(childButton, dateToAdd);
                    childButton.DataContext = dateToAdd;
                    childButton.SetContentInternal(DateTimeHelper.ToDayString(dateToAdd, culture));
                }
                else
                {
                    SetMonthModeDayButtonState(childButton, null);
                    childButton.DataContext = null;
                    childButton.SetContentInternal(DateTimeHelper.ToDayString(null, culture));
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Common PropertyChangedCallback for dependency properties that trigger visual state changes
        /// </summary>
        /// <param name="dObject"></param>
        /// <param name="e"></param>
        private static void OnVisualStatePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            CalendarDayButton dayButton = sender as CalendarDayButton;

            if (dayButton != null)
            {
                dayButton.ChangeVisualState(true);
            }
        }
Пример #6
0
        private void Cell_MouseLeave(object sender, MouseEventArgs e)
        {
            CalendarDayButton b = sender as CalendarDayButton;

            if (b == null)
            {
                return;
            }
        }
Пример #7
0
        private void AddMonthModeHighlight()
        {
            var owner = this.Owner;

            if (owner == null)
            {
                return;
            }

            if (owner.HoverStart.HasValue && owner.HoverEnd.HasValue)
            {
                DateTime hStart = owner.HoverEnd.Value;
                DateTime hEnd   = owner.HoverEnd.Value;

                int daysToHighlight = DateTimeHelper.CompareDays(owner.HoverEnd.Value, owner.HoverStart.Value);
                if (daysToHighlight < 0)
                {
                    hEnd = this.Owner.HoverStart.Value;
                }
                else
                {
                    hStart = this.Owner.HoverStart.Value;
                }

                int count = ROWS * COLS;

                for (int childIndex = COLS; childIndex < count; childIndex++)
                {
                    CalendarDayButton childButton = _monthView.Children[childIndex] as CalendarDayButton;
                    if (childButton.DataContext is DateTime)
                    {
                        DateTime date = (DateTime)childButton.DataContext;
                        childButton.SetValue(
                            CalendarDayButton.IsHighlightedPropertyKey,
                            (daysToHighlight != 0) && DateTimeHelper.InRange(date, hStart, hEnd));
                    }
                    else
                    {
                        childButton.SetValue(CalendarDayButton.IsHighlightedPropertyKey, false);
                    }
                }
            }
            else
            {
                int count = ROWS * COLS;

                for (int childIndex = COLS; childIndex < count; childIndex++)
                {
                    CalendarDayButton childButton = _monthView.Children[childIndex] as CalendarDayButton;
                    childButton.SetValue(CalendarDayButton.IsHighlightedPropertyKey, false);
                }
            }
        }
Пример #8
0
        private static object OnCoerceContent(DependencyObject sender, object baseValue)
        {
            CalendarDayButton button = (CalendarDayButton)sender;

            if (button._shouldCoerceContent)
            {
                button._shouldCoerceContent = false;
                return(button._coercedContent);
            }

            return(baseValue);
        }
Пример #9
0
        private void Cell_MouseEnter(object sender, MouseEventArgs e)
        {
            CalendarDayButton b = sender as CalendarDayButton;

            if (b == null)
            {
                return;
            }

            if (b.IsBlackedOut)
            {
                return;
            }

            if (e.LeftButton == MouseButtonState.Pressed && this._isDayPressed)
            {
                b.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));

                if (this.Owner == null || !(b.DataContext is DateTime))
                {
                    return;
                }

                DateTime selectedDate = (DateTime)b.DataContext;

                switch (this.Owner.SelectionMode)
                {
                case CalendarSelectionMode.SingleDate:
                {
                    this.Owner.DatePickerDisplayDateFlag = true;
                    this.Owner.HoverStart = this.Owner.HoverEnd = null;
                    if (this.Owner.SelectedDates.Count == 0)
                    {
                        this.Owner.SelectedDates.Add(selectedDate);
                    }
                    else
                    {
                        this.Owner.SelectedDates[0] = selectedDate;
                    }

                    return;
                }
                }

                this.Owner.HoverEnd    = selectedDate;
                this.Owner.CurrentDate = selectedDate;
                this.Owner.UpdateCellItems();
            }
        }
Пример #10
0
        internal IEnumerable <CalendarDayButton> GetCalendarDayButtons()
        {
            // TODO: should be updated if we support MultiCalendar
            int count = ROWS * COLS;

            if (MonthView != null)
            {
                UIElementCollection dayButtonsHost = MonthView.Children;
                for (int childIndex = COLS; childIndex < count; childIndex++)
                {
                    CalendarDayButton b = dayButtonsHost[childIndex] as CalendarDayButton;
                    if (b != null)
                    {
                        yield return(b);
                    }
                }
            }
        }
Пример #11
0
        private void FinishSelection(DateTime selectedDate)
        {
            bool ctrl, shift;

            KeyboardHelper.GetMetaKeyState(out ctrl, out shift);

            if (this.Owner.SelectionMode == CalendarSelectionMode.None || this.Owner.SelectionMode == CalendarSelectionMode.SingleDate)
            {
                this.Owner.OnDayClick(selectedDate);
                return;
            }

            if (this.Owner.HoverStart.HasValue)
            {
                switch (this.Owner.SelectionMode)
                {
                case CalendarSelectionMode.SingleRange:
                {
                    // Update SelectedDates
                    this.Owner.SelectedDates.ClearInternal();
                    EndDrag(ctrl, selectedDate);
                    break;
                }

                case CalendarSelectionMode.MultipleRange:
                {
                    // add the selection (either single day or SingleRange day)
                    EndDrag(ctrl, selectedDate);
                    break;
                }
                }
            }
            else
            {
                // If the day is blacked out but also a trailing day we should be able to switch months
                CalendarDayButton b = GetCalendarDayButton(selectedDate);
                if (b != null && b.IsInactive && b.IsBlackedOut)
                {
                    this.Owner.OnDayClick(selectedDate);
                }
            }
        }
Пример #12
0
        private void SetMonthModeDayButtonState(CalendarDayButton childButton, DateTime?dateToAdd)
        {
            if (this.Owner != null)
            {
                if (dateToAdd.HasValue)
                {
                    childButton.Visibility = Visibility.Visible;

                    // If the day is outside the DisplayDateStart/End boundary, do not show it
                    if (DateTimeHelper.CompareDays(dateToAdd.Value, this.Owner.DisplayDateStartInternal) < 0 || DateTimeHelper.CompareDays(dateToAdd.Value, this.Owner.DisplayDateEndInternal) > 0)
                    {
                        childButton.IsEnabled  = false;
                        childButton.Visibility = Visibility.Hidden;
                    }
                    else
                    {
                        childButton.IsEnabled = true;

                        // SET IF THE DAY IS SELECTABLE OR NOT
                        childButton.SetValue(
                            CalendarDayButton.IsBlackedOutPropertyKey,
                            this.Owner.BlackoutDates.Contains(dateToAdd.Value));

                        // SET IF THE DAY IS ACTIVE OR NOT: set if the day is a trailing day or not
                        childButton.SetValue(
                            CalendarDayButton.IsInactivePropertyKey,
                            DateTimeHelper.CompareYearMonth(dateToAdd.Value, this.Owner.DisplayDateInternal) != 0);

                        // SET IF THE DAY IS TODAY OR NOT
                        if (DateTimeHelper.CompareDays(dateToAdd.Value, DateTime.Today) == 0)
                        {
                            childButton.SetValue(CalendarDayButton.IsTodayPropertyKey, true);

                            // Calendar.IsTodayHighlighted affects the final visual state for Today buttons
                            // but childButton property change callbacks are no called in response to
                            // Calendar.IsTodayHighlighted changing so we must explicitly update the visual state
                            childButton.ChangeVisualState(true);
                        }
                        else
                        {
                            childButton.SetValue(CalendarDayButton.IsTodayPropertyKey, false);
                        }

                        // SET IF THE DAY IS SELECTED OR NOT
                        // Since we should be comparing the Date values not DateTime values, we can't use this.Owner.SelectedDates.Contains(dateToAdd) directly
                        bool isSelected = false;
                        foreach (DateTime item in this.Owner.SelectedDates)
                        {
                            isSelected |= (DateTimeHelper.CompareDays(dateToAdd.Value, item) == 0);
                        }

                        childButton.SetValue(CalendarDayButton.IsSelectedPropertyKey, isSelected);
                    }
                }
                else
                {
                    childButton.Visibility = Visibility.Hidden;
                    childButton.IsEnabled  = false;
                    childButton.SetValue(CalendarDayButton.IsBlackedOutPropertyKey, false);
                    childButton.SetValue(CalendarDayButton.IsInactivePropertyKey, true);
                    childButton.SetValue(CalendarDayButton.IsTodayPropertyKey, false);
                    childButton.SetValue(CalendarDayButton.IsSelectedPropertyKey, false);
                }
            }
        }
Пример #13
0
        private void Cell_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            CalendarDayButton b = sender as CalendarDayButton;

            if (b == null)
            {
                return;
            }

            if (this.Owner == null)
            {
                return;
            }

            if (!b.IsBlackedOut)
            {
                this.Owner.OnDayButtonMouseUp(e);
            }

            if (!(b.DataContext is DateTime))
            {
                return;
            }

            bool ctrl, shift;

            KeyboardHelper.GetMetaKeyState(out ctrl, out shift);

            if (this.Owner.SelectionMode == CalendarSelectionMode.None || this.Owner.SelectionMode == CalendarSelectionMode.SingleDate)
            {
                this.Owner.OnDayClick((DateTime)b.DataContext);
                return;
            }

            if (this.Owner.HoverStart.HasValue)
            {
                switch (this.Owner.SelectionMode)
                {
                case CalendarSelectionMode.SingleRange:
                {
                    // Update SelectedDates
                    this.Owner.SelectedDates.ClearInternal();
                    EndDrag(ctrl, b);
                    break;
                }

                case CalendarSelectionMode.MultipleRange:
                {
                    // add the selection (either single day or SingleRange day)
                    EndDrag(ctrl, b);
                    break;
                }
                }
            }
            else
            {
                // If the day is blacked out but also a trailing day we should be able to switch months
                if (b.IsInactive && b.IsBlackedOut)
                {
                    this.Owner.OnDayClick((DateTime)b.DataContext);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the CalendarDayButtonAutomationPeer class.
 /// </summary>
 /// <param name="owner">Owning CalendarDayButton</param>
 public CalendarDayButtonAutomationPeer(CalendarDayButton owner)
     : base(owner)
 {
 }
Пример #15
0
        private void Cell_Clicked(object sender, RoutedEventArgs e)
        {
            if (this.Owner == null)
            {
                return;
            }

            CalendarDayButton b = sender as CalendarDayButton;

            Debug.Assert(b != null);

            if (!(b.DataContext is DateTime))
            {
                return;
            }

            // If the day is a blackout day selection is not allowed
            if (!b.IsBlackedOut)
            {
                DateTime clickedDate = (DateTime)b.DataContext;
                bool     ctrl, shift;

                KeyboardHelper.GetMetaKeyState(out ctrl, out shift);

                switch (this.Owner.SelectionMode)
                {
                case CalendarSelectionMode.None:
                {
                    break;
                }

                case CalendarSelectionMode.SingleDate:
                {
                    if (!ctrl)
                    {
                        this.Owner.SelectedDate = clickedDate;
                    }
                    else
                    {
                        this.Owner.SelectedDates.Toggle(clickedDate);
                    }

                    break;
                }

                case CalendarSelectionMode.SingleRange:
                {
                    DateTime?lastDate = this.Owner.CurrentDate;
                    this.Owner.SelectedDates.ClearInternal(true /*fireChangeNotification*/);
                    if (shift && lastDate.HasValue)
                    {
                        this.Owner.SelectedDates.AddRangeInternal(lastDate.Value, clickedDate);
                    }
                    else
                    {
                        this.Owner.SelectedDate = clickedDate;
                        this.Owner.HoverStart   = null;
                        this.Owner.HoverEnd     = null;
                    }

                    break;
                }

                case CalendarSelectionMode.MultipleRange:
                {
                    if (!ctrl)
                    {
                        this.Owner.SelectedDates.ClearInternal(true /*fireChangeNotification*/);
                    }

                    if (shift)
                    {
                        this.Owner.SelectedDates.AddRangeInternal(this.Owner.CurrentDate, clickedDate);
                    }
                    else
                    {
                        if (!ctrl)
                        {
                            this.Owner.SelectedDate = clickedDate;
                        }
                        else
                        {
                            this.Owner.SelectedDates.Toggle(clickedDate);
                            this.Owner.HoverStart = null;
                            this.Owner.HoverEnd   = null;
                        }
                    }

                    break;
                }
                }

                this.Owner.OnDayClick(clickedDate);
            }
        }
Пример #16
0
        private void Cell_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            CalendarDayButton b = sender as CalendarDayButton;

            if (b == null)
            {
                return;
            }

            if (this.Owner == null || !(b.DataContext is DateTime))
            {
                return;
            }

            if (b.IsBlackedOut)
            {
                this.Owner.HoverStart = null;
            }
            else
            {
                this._isDayPressed = true;
                Mouse.Capture(this, CaptureMode.SubTree);

                b.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));

                bool ctrl, shift;
                KeyboardHelper.GetMetaKeyState(out ctrl, out shift);

                DateTime selectedDate = (DateTime)b.DataContext;
                Debug.Assert(selectedDate != null);

                switch (this.Owner.SelectionMode)
                {
                case CalendarSelectionMode.None:
                {
                    break;
                }

                case CalendarSelectionMode.SingleDate:
                {
                    this.Owner.DatePickerDisplayDateFlag = true;
                    if (!ctrl)
                    {
                        this.Owner.SelectedDate = selectedDate;
                    }
                    else
                    {
                        this.Owner.SelectedDates.Toggle(selectedDate);
                    }

                    break;
                }

                case CalendarSelectionMode.SingleRange:
                {
                    this.Owner.SelectedDates.ClearInternal();

                    if (shift)
                    {
                        if (!this.Owner.HoverStart.HasValue)
                        {
                            this.Owner.HoverStart = this.Owner.HoverEnd = this.Owner.CurrentDate;
                        }
                    }
                    else
                    {
                        this.Owner.HoverStart = this.Owner.HoverEnd = selectedDate;
                    }

                    break;
                }

                case CalendarSelectionMode.MultipleRange:
                {
                    if (!ctrl)
                    {
                        this.Owner.SelectedDates.ClearInternal();
                    }

                    if (shift)
                    {
                        if (!this.Owner.HoverStart.HasValue)
                        {
                            this.Owner.HoverStart = this.Owner.HoverEnd = this.Owner.CurrentDate;
                        }
                    }
                    else
                    {
                        this.Owner.HoverStart = this.Owner.HoverEnd = selectedDate;
                    }

                    break;
                }
                }

                this.Owner.CurrentDate = selectedDate;
                this.Owner.UpdateCellItems();
            }
        }
Пример #17
0
        private void SetMonthModeDayButtonState(CalendarDayButton childButton, DateTime? dateToAdd)
        {
            if (this.Owner != null)
            {
                if (dateToAdd.HasValue)
                {
                    childButton.Visibility = Visibility.Visible;

                    // If the day is outside the DisplayDateStart/End boundary, do not show it
                    if (DateTimeHelper.CompareDays(dateToAdd.Value, this.Owner.DisplayDateStartInternal) < 0 || DateTimeHelper.CompareDays(dateToAdd.Value, this.Owner.DisplayDateEndInternal) > 0)
                    {
                        childButton.IsEnabled = false;
                        childButton.Visibility = Visibility.Hidden;
                    }
                    else
                    {
                        childButton.IsEnabled = true;

                        // SET IF THE DAY IS SELECTABLE OR NOT
                        childButton.SetValue(
                            CalendarDayButton.IsBlackedOutPropertyKey, 
                            this.Owner.BlackoutDates.Contains(dateToAdd.Value));

                        // SET IF THE DAY IS ACTIVE OR NOT: set if the day is a trailing day or not
                        childButton.SetValue(
                            CalendarDayButton.IsInactivePropertyKey, 
                            DateTimeHelper.CompareYearMonth(dateToAdd.Value, this.Owner.DisplayDateInternal) != 0);

                        // SET IF THE DAY IS TODAY OR NOT
                        if (DateTimeHelper.CompareDays(dateToAdd.Value, DateTime.Today) == 0)
                        {
                            childButton.SetValue(CalendarDayButton.IsTodayPropertyKey, true);
                            
                            // Calendar.IsTodayHighlighted affects the final visual state for Today buttons 
                            // but childButton property change callbacks are no called in response to 
                            // Calendar.IsTodayHighlighted changing so we must explicitly update the visual state
                            childButton.ChangeVisualState(true);
                        }
                        else
                        {
                            childButton.SetValue(CalendarDayButton.IsTodayPropertyKey, false);
                        }

                        // SET IF THE DAY IS SELECTED OR NOT
                        // Since we should be comparing the Date values not DateTime values, we can't use this.Owner.SelectedDates.Contains(dateToAdd) directly
                        bool isSelected = false;
                        foreach (DateTime item in this.Owner.SelectedDates)
                        {
                            isSelected |= (DateTimeHelper.CompareDays(dateToAdd.Value, item) == 0);                            
                        }

                        childButton.SetValue(CalendarDayButton.IsSelectedPropertyKey, isSelected);
                    }
                }
                else
                {
                    childButton.Visibility = Visibility.Hidden;
                    childButton.IsEnabled = false;
                    childButton.SetValue(CalendarDayButton.IsBlackedOutPropertyKey, false);
                    childButton.SetValue(CalendarDayButton.IsInactivePropertyKey, true);
                    childButton.SetValue(CalendarDayButton.IsTodayPropertyKey, false);
                    childButton.SetValue(CalendarDayButton.IsSelectedPropertyKey, false);
                }
            }
        }
Пример #18
0
        private void PopulateGrids()
        {
            if (_monthView != null)
            {
                if (_dayTitleTemplate != null)
                {
                    for (int i = 0; i < COLS; i++)
                    {
                        FrameworkElement titleCell = (FrameworkElement)this._dayTitleTemplate.LoadContent();
                        titleCell.SetValue(Grid.RowProperty, 0);
                        titleCell.SetValue(Grid.ColumnProperty, i);
                        this._monthView.Children.Add(titleCell);
                    }
                }

                for (int i = 1; i < ROWS; i++)
                {
                    for (int j = 0; j < COLS; j++)
                    {
                        CalendarDayButton dayCell = new CalendarDayButton();

                        dayCell.Owner = this.Owner;
                        dayCell.SetValue(Grid.RowProperty, i);
                        dayCell.SetValue(Grid.ColumnProperty, j);
                        dayCell.SetBinding(CalendarDayButton.StyleProperty, GetOwnerBinding("CalendarDayButtonStyle"));
                        dayCell.AddHandler(CalendarDayButton.MouseLeftButtonDownEvent, new MouseButtonEventHandler(Cell_MouseLeftButtonDown), true);
                        dayCell.AddHandler(CalendarDayButton.MouseLeftButtonUpEvent, new MouseButtonEventHandler(Cell_MouseLeftButtonUp), true);
                        dayCell.AddHandler(CalendarDayButton.MouseEnterEvent, new MouseEventHandler(Cell_MouseEnter), true);
                        dayCell.Click += new RoutedEventHandler(Cell_Clicked);
                        dayCell.AddHandler(PreviewKeyDownEvent, new RoutedEventHandler(CellOrMonth_PreviewKeyDown), true);

                        this._monthView.Children.Add(dayCell);
                    }
                }
            }

            if (_yearView != null)
            {
                CalendarButton monthCell;
                int count = 0;
                for (int i = 0; i < YEAR_ROWS; i++)
                {
                    for (int j = 0; j < YEAR_COLS; j++)
                    {
                        monthCell = new CalendarButton();

                        monthCell.Owner = this.Owner;
                        monthCell.SetValue(Grid.RowProperty, i);
                        monthCell.SetValue(Grid.ColumnProperty, j);
                        monthCell.SetBinding(CalendarButton.StyleProperty, GetOwnerBinding("CalendarButtonStyle"));
                        monthCell.AddHandler(CalendarButton.MouseLeftButtonDownEvent, new MouseButtonEventHandler(Month_MouseLeftButtonDown), true);
                        monthCell.AddHandler(CalendarButton.MouseLeftButtonUpEvent, new MouseButtonEventHandler(Month_MouseLeftButtonUp), true);
                        monthCell.AddHandler(CalendarButton.MouseEnterEvent, new MouseEventHandler(Month_MouseEnter), true);
                        monthCell.AddHandler(UIElement.PreviewKeyDownEvent, new RoutedEventHandler(CellOrMonth_PreviewKeyDown), true);
                        monthCell.Click += new RoutedEventHandler(Month_Clicked);
                        this._yearView.Children.Add(monthCell);
                        count++;
                    }
                }
            }
        }
Пример #19
0
        private void EndDrag(bool ctrl, CalendarDayButton b)
        {
            if (this.Owner != null && b.DataContext is DateTime)
            {
                DateTime selectedDate = (DateTime)b.DataContext;
                this.Owner.CurrentDate = selectedDate;

                if (this.Owner.HoverStart.HasValue)
                {
                    if (
                        ctrl &&
                        DateTime.Compare(this.Owner.HoverStart.Value, selectedDate) == 0 &&
                        (Owner.SelectionMode == CalendarSelectionMode.SingleDate || Owner.SelectionMode == CalendarSelectionMode.MultipleRange))
                    {
                        // Ctrl + single click = toggle
                        this.Owner.SelectedDates.Toggle(selectedDate);
                    }
                    else
                    {
                        // this is selection with Mouse, we do not guarantee the range does not include BlackOutDates.
                        // Use the internal AddRange that omits BlackOutDates based on the SelectionMode
                        this.Owner.SelectedDates.AddRangeInternal(this.Owner.HoverStart.Value, selectedDate);
                    }

                    Owner.OnDayClick(selectedDate);
                }
            }
        }