Наследование: System.Windows.Controls.Control
Пример #1
0
        private void GenerateItems()
        {
            if (Node == null)
            {
                ItemsPresenter.Children.Clear();
            }
            else if (!ItemsValid)
            {
                ItemsValid = true;
                ItemsPresenter.Children.Clear();

                GanttItem item = null;


                if (Node.Sections.Count == 1)
                {
                    if (Node.ChildNodes.Count == 0)
                    {
                        item = new GanttItem();
                    }
                    else
                    {
                        item = new HeaderGanttItem();
                    }

                    item.GapBackgroundBrush     = this.GapBackgroundBrush;
                    item.GapBorderBrush         = this.GapBorderBrush;
                    item.ToolTipContent         = this.Node;
                    item.ToolTipContentTemplate = this.ParentPanel.ToolTipContentTemplate;
                    item.Section   = Node.Sections[0];
                    item.ParentRow = this;
                    item.Node      = Node;
                    ItemsPresenter.Children.Add(item);
                }
                else
                {
                    foreach (GanttNodeSection section in Node.Sections)
                    {
                        item = new GanttItem();

                        if (section.BackgroundBrush != null)
                        {
                            item.Background = section.BackgroundBrush;
                        }

                        item.ToolTipContent         = this.Node;
                        item.ToolTipContentTemplate = this.ParentPanel.ToolTipContentTemplate;
                        item.ParentRow = this;
                        item.Node      = Node;
                        item.Section   = section;
                        ItemsPresenter.Children.Add(item);
                    }
                }
            }
        }
Пример #2
0
        private void UpdateDependencies(GanttItem ganttItem)
        {
            var deps = Dependencies.Where(d => d.ChildNode == ganttItem.Node || d.ParentNode == ganttItem.Node);

            var items = DependencyPresenter.Children.Cast <UIElement>().Where(ui => (ui as GanttDependencyItem).Dependency.ChildNode == ganttItem.Node || (ui as GanttDependencyItem).Dependency.ParentNode == ganttItem.Node);

            foreach (UIElement ui in items)
            {
                (ui as GanttDependencyItem).UpdateDependencyLines();
            }
        }
Пример #3
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            Debug.WriteLine("GanttItemsPresenter.ArrangeOverride()");
            for (int i = 0; i < Children.Count; i++)
            {
                GanttItem gi = (GanttItem)Children[i];

                double x1, x2;
                //Actual item
                x1 = ParentRow.ParentPanel.ConvertDateToPosition(gi.Section.StartDate);
                x2 = ParentRow.ParentPanel.ConvertDateToPosition(gi.Section.EndDate);
                double width = x2 - x1;

                double x3 = 0d;

                //Gap
                if (gi.Node.ShowGap && i == Children.Count - 1 && ParentRow.RowIndex < ParentRow.ParentPanel.Nodes.Count - 1)
                {
                    IGanttNode nextNode = ParentRow.ParentPanel.Nodes[ParentRow.RowIndex + 1];

                    if (nextNode.StartDate > gi.Node.EndDate && nextNode.ParentNode == gi.Node.ParentNode)
                    {
                        x3     = ParentRow.ParentPanel.ConvertDateToPosition(nextNode.StartDate);
                        width += x3 - x2;
                    }
                }

                if (width > 0)
                {
                    gi.Arrange(new Rect(x1, 0, width, ParentRow.ActualHeight));
                }
                else
                {
                    gi.Arrange(new Rect(0, 0, 0, ParentRow.ActualHeight));
                }
            }
            return(base.ArrangeOverride(finalSize));
        }
Пример #4
0
        protected override Size MeasureOverride(Size availableSize)
        {
            Debug.WriteLine("GanttItemsPresenter.MeasureOverride(" + availableSize.ToString() + ")");
            for (int i = 0; i < Children.Count; i++)
            {
                GanttItem gi = (GanttItem)Children[i];

                double x1, x2;
                x1 = ParentRow.ParentPanel.ConvertDateToPosition(gi.Section.StartDate);
                x2 = ParentRow.ParentPanel.ConvertDateToPosition(gi.Section.EndDate);
                double width = x2 - x1;

                double x3 = 0d;

                //Gap
                if (gi.Node.ShowGap && i == Children.Count - 1 && ParentRow.RowIndex < ParentRow.ParentPanel.Nodes.Count - 1)
                {
                    IGanttNode nextNode = ParentRow.ParentPanel.Nodes[ParentRow.RowIndex + 1];

                    if (nextNode.StartDate > gi.Node.EndDate && nextNode.ParentNode == gi.Node.ParentNode)
                    {
                        x3     = ParentRow.ParentPanel.ConvertDateToPosition(nextNode.StartDate);
                        width += x3 - x2;
                    }
                }

                if (width < 0)
                {
                    width = 0;
                }

                gi.Measure(new Size(width, ParentRow.ActualHeight));
            }

            return(base.MeasureOverride(availableSize));
        }
Пример #5
0
        private void UpdateDependencies(GanttItem ganttItem)
        {
            var deps = Dependencies.Where(d => d.ChildNode == ganttItem.Node || d.ParentNode == ganttItem.Node);

            var items = DependencyPresenter.Children.Cast<UIElement>().Where(ui => (ui as GanttDependencyItem).Dependency.ChildNode == ganttItem.Node || (ui as GanttDependencyItem).Dependency.ParentNode == ganttItem.Node);

            foreach (UIElement ui in items)
            {
                (ui as GanttDependencyItem).UpdateDependencyLines();
            }
        }
Пример #6
0
 public GanttItemEventArgs(GanttItem item)
 {
     Item = item;
 }
Пример #7
0
        private void GenerateItems()
        {
            if (Node == null)
            {
                ItemsPresenter.Children.Clear();
            }
            else if (!ItemsValid)
            {
                ItemsValid = true;
                ItemsPresenter.Children.Clear();

                GanttItem item = null;

                if (Node.Sections.Count == 1)
                {
                    if (Node.ChildNodes.Count == 0)
                        item = new GanttItem();
                    else
                        item = new HeaderGanttItem();

                    item.GapBackgroundBrush = this.GapBackgroundBrush;
                    item.GapBorderBrush = this.GapBorderBrush;
                    item.ToolTipContent = this.Node;
                    item.ToolTipContentTemplate = this.ParentPanel.ToolTipContentTemplate;
                    item.Section = Node.Sections[0];
                    item.ParentRow = this;
                    item.Node = Node;
                    ItemsPresenter.Children.Add(item);
                }
                else
                {
                    foreach (GanttNodeSection section in Node.Sections)
                    {
                        item = new GanttItem();

                        if(section.BackgroundBrush != null)
                            item.Background = section.BackgroundBrush;

                        item.ToolTipContent = this.Node;
                        item.ToolTipContentTemplate = this.ParentPanel.ToolTipContentTemplate;
                        item.ParentRow = this;
                        item.Node = Node;
                        item.Section = section;
                        ItemsPresenter.Children.Add(item);
                    }
                }
            }
        }
 public GanttItemEventArgs(GanttItem item)
 {
     Item = item;
 }
Пример #9
0
        private void GanttRow_MouseMove(object sender, MouseEventArgs e)
        {
            _sameSizeCnt = 1;

            if (_ProcessingMove || IsReadOnly)
            {
                return;
            }
            else
            {
                _ProcessingMove = true;
            }

            Point cursorPosition = e.GetPosition(this.RootUI());

            List <GanttItem> items = ItemsPresenter.Children.OfType <GanttItem>().ToList();

            for (int i = 0; i < items.Count; i++)
            {
                GanttItem item = items[i];

                GeneralTransform gt           = item.TransformToVisual(this.RootUI());
                Point            itemPosition = gt.Transform(new Point(0, 0));

                double distance = 0d;
                distance = cursorPosition.X - _DragStart.X;

                if (item.DragState == DragState.ResizeLeft)
                {
                    Cursor = Cursors.SizeWE;
                }
                else if (item.DragState == DragState.ResizeRight)
                {
                    Cursor = Cursors.SizeWE;
                }
                else if (item.DragState == DragState.Whole)
                {
                    Cursor = Cursors.Hand;
                }
                else
                {
                    _ProcessingMove = false;
                    continue;
                }

                TimeSpan ts = GetTimeSpanFromDistance(distance);

#if DEBUG
                ParentPanel.Content = item.Name;
                ParentPanel.Content = distance.ToString() + "   " + ts.ToString() + " " + item.DragState.ToString();
#endif

                if (Math.Abs(ts.TotalDays) >= 1)
                {
                    if (item.DragState == DragState.ResizeLeft)
                    {
                        ParentPanel.RaiseItemChanging(new GanttItemEventArgs(item));
                        DateTime newDate = item.Section.StartDate.Add(ts);

                        if (newDate < item.Section.EndDate)
                        {
                            item.Section.StartDate = newDate;
                            item.InvalidateMeasure();

                            if (RowIndex > 0)
                            {
                                (ParentPanel.RowPresenter.Children[RowIndex - 1] as GanttRow).Invalidate();
                            }
                        }
                        ParentPanel.RaiseItemChanged(new GanttItemEventArgs(item));
                    }
                    else if (item.DragState == DragState.ResizeRight)
                    {
                        ParentPanel.RaiseItemChanging(new GanttItemEventArgs(item));
                        DateTime newDate = item.Section.EndDate.Add(ts);

                        if (newDate > item.Section.StartDate)
                        {
                            item.Section.EndDate = newDate;
                            item.InvalidateMeasure();

                            if (RowIndex > 0)
                            {
                                (ParentPanel.RowPresenter.Children[RowIndex - 1] as GanttRow).Invalidate();
                            }
                        }

                        ParentPanel.RaiseItemChanged(new GanttItemEventArgs(item));
                    }
                    else if (item.DragState == DragState.Whole)
                    {
                        ParentPanel.RaiseItemChanging(new GanttItemEventArgs(item));

                        DateTime newStart = item.Section.StartDate.Add(ts);
                        DateTime newEnd   = item.Section.EndDate.Add(ts);

                        if (distance > 0)
                        {
                            item.Section.EndDate   = newEnd;
                            item.Section.StartDate = newStart;
                        }
                        else
                        {
                            item.Section.StartDate = newStart;
                            item.Section.EndDate   = newEnd;
                        }
                        Invalidate();

                        // item.InvalidateArrange();
                        if (RowIndex > 0)
                        {
                            (ParentPanel.RowPresenter.Children[RowIndex - 1] as GanttRow).Invalidate();
                        }

                        ParentPanel.RaiseItemChanged(new GanttItemEventArgs(item));
                    }

                    _DragStart = e.GetPosition(this.RootUI());
                }
            }

            _ProcessingMove = false;
        }