コード例 #1
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);

            ICalendarSelectableElement hitted = HitTest(e.GetPosition(this));
            CalendarItem hittedItem           = hitted as CalendarItem;
            bool         shiftPressed         = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift);

            if (!Focused)
            {
                Focus();
            }

            switch (State)
            {
            case CalendarState.Idle:
                if (hittedItem != null)
                {
                    if (!shiftPressed)
                    {
                        ClearSelectedItems();
                    }

                    hittedItem.SetSelected(true);
                    Invalidate(hittedItem);
                    OnItemSelected(new CalendarItemEventArgs(hittedItem));

                    itemOnState        = hittedItem;
                    itemOnStateChanged = false;

                    if (AllowItemEdit)
                    {
                        if (itemOnState.ResizeStartDateZone(e.GetPosition(this)) && AllowItemResize)
                        {
                            SetState(CalendarState.ResizingItem);
                            itemOnState.SetIsResizingStartDate(true);
                        }
                        else if (itemOnState.ResizeEndDateZone(e.GetPosition(this)) && AllowItemResize)
                        {
                            SetState(CalendarState.ResizingItem);
                            itemOnState.SetIsResizingEndDate(true);
                        }
                        else
                        {
                            SetState(CalendarState.DraggingItem);
                        }
                    }

                    SetSelectionRange(null, null);
                }
                else
                {
                    ClearSelectedItems();

                    if (shiftPressed)
                    {
                        if (hitted != null && SelectedElementEnd == null && !SelectedElementEnd.Equals(hitted))
                        {
                            SelectedElementEnd = hitted;
                        }
                    }
                    else
                    {
                        if (SelectedElementStart == null || (hitted != null && !SelectedElementStart.Equals(hitted)))
                        {
                            SetSelectionRange(hitted, hitted);
                        }
                    }

                    SetState(CalendarState.DraggingTimeSelection);
                }
                break;

            case CalendarState.DraggingTimeSelection:
                break;

            case CalendarState.DraggingItem:
                break;

            case CalendarState.ResizingItem:
                break;

            case CalendarState.EditingItemText:
                break;
            }
        }