Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
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();
            }
        }