Ejemplo n.º 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;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Remove virtual appointment item from it's parent panel
        /// </summary>
        /// <param name="appointmentItem"></param>
        public void RemoveVirtualAppointmentItem(PlannerAppointmentItem appointmentItem)
        {
            if (appointmentItem == null)
            {
                return;
            }
            PlannerTimelinePanel panel = appointmentItem.Parent as PlannerTimelinePanel;

            if (panel != null)
            {
                panel.Children.Remove(appointmentItem);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Preview virtual appointment item on a virtual panel
        /// </summary>
        /// <param name="appointmentItem"></param>
        public void PreviewVirtualAppointmentItem(PlannerAppointmentItem appointmentItem)
        {
            PlannerEntity targetEntity = PlannerHelper.FindVisualChild <PlannerEntity>(this).Find(_ => VisualTreeHelper.HitTest(_, Mouse.GetPosition(_)) != null);

            if (targetEntity != null)
            {
                if (appointmentItem.Parent != null)
                {
                    if (appointmentItem.Parent == targetEntity.GetVirtualPanel())
                    {
                        return;
                    }
                    PlannerTimelinePanel currentPanel = appointmentItem.Parent as PlannerTimelinePanel;
                    currentPanel.Children.Remove(appointmentItem);
                }

                PlannerTimelinePanel virtualPanel = targetEntity.GetVirtualPanel();
                virtualPanel.Children.Add(appointmentItem);
            }
        }
Ejemplo n.º 4
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;
        }