示例#1
0
        /// <summary>
        /// Event handler on thumb is dragged
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnDragDelta(object sender, DragDeltaEventArgs e)
        {
            if (sender == _thumbMove)
            {
                PlannerTimelinePanel timelinePanel = VisualParent as PlannerTimelinePanel;
                if (timelinePanel != null)
                {
                    if (VisualTreeHelper.HitTest(timelinePanel, Mouse.GetPosition(timelinePanel)) == null)
                    {
                        if (_virtualAppointmentItem == null)
                        {
                            _virtualAppointmentItem             = new PlannerVirtualAppointmentItem();
                            _virtualAppointmentItem.DataContext = DataContext;
                        }
                        Planner planner = PlannerHelper.FindVisualParent <Planner>(timelinePanel);
                        planner.PreviewVirtualAppointmentItem(_virtualAppointmentItem);
                    }
                    else
                    {
                        if (_virtualAppointmentItem != null)
                        {
                            Planner planner = PlannerHelper.FindVisualParent <Planner>(timelinePanel);
                            planner.RemoveVirtualAppointmentItem(_virtualAppointmentItem);
                            _virtualAppointmentItem = null;
                        }
                    }
                }

                if (_virtualAppointmentItem != null)
                {
                    _virtualAppointmentItem.Arrange(new Rect(VisualOffset.X + e.HorizontalChange, VisualOffset.Y, ActualWidth, ActualHeight));
                }

                Arrange(new Rect(VisualOffset.X + e.HorizontalChange, VisualOffset.Y, ActualWidth, ActualHeight));
            }
            else if (sender == _thumbLeft)
            {
                double width = ActualWidth - e.HorizontalChange;
                if (width < 10)
                {
                    width = 10;
                }

                Width = width;
                Arrange(new Rect(VisualOffset.X + e.HorizontalChange, VisualOffset.Y, width, ActualHeight));
            }
            else if (sender == _thumbRight)
            {
                double width = ActualWidth + e.HorizontalChange;
                if (width < 10)
                {
                    width = 10;
                }

                Width = width;
                Arrange(new Rect(VisualOffset.X, VisualOffset.Y, width, ActualHeight));
            }

            e.Handled = true;
        }
示例#2
0
        /// <summary>
        /// Event handler on thumb drag is completed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnDragCompleted(object sender, DragCompletedEventArgs e)
        {
            PlannerTimelinePanel timelinePanel = PlannerHelper.FindVisualParent <PlannerTimelinePanel>(this);

            if (timelinePanel == null)
            {
                return;
            }

            if (sender == _thumbMove)
            {
                TimeSpan timeSpan = End - Start;
                Start = timelinePanel.CalculateDateTime(VisualOffset.X);
                End   = Start + timeSpan;

                if (_virtualAppointmentItem != null)
                {
                    IPlannerEntity currentEntity = PlannerHelper.FindVisualParent <PlannerEntity>(this).DataContext as IPlannerEntity;
                    IPlannerEntity targetEntity  = PlannerHelper.FindVisualParent <PlannerEntity>(_virtualAppointmentItem).DataContext as IPlannerEntity;
                    IAppointment   appointment   = DataContext as IAppointment;

                    currentEntity.Appointments.Remove(appointment);
                    targetEntity.Appointments.Add(appointment);

                    Planner planner = PlannerHelper.FindVisualParent <Planner>(timelinePanel);
                    planner.RemoveVirtualAppointmentItem(_virtualAppointmentItem);
                    _virtualAppointmentItem = null;
                }
            }
            else if (sender == _thumbLeft)
            {
                Start = timelinePanel.CalculateDateTime(VisualOffset.X);
            }
            else if (sender == _thumbRight)
            {
                End = timelinePanel.CalculateDateTime(VisualOffset.X + ActualWidth);
            }

            e.Handled = true;
        }