Exemplo n.º 1
0
        private StackPanel GeneratePanel(object dataItem)
        {
            StackPanel panel = new StackPanel();

            panel.Orientation = Orientation.Horizontal;

            IGanttNode node = (IGanttNode)dataItem;

            Binding bind = new Binding("Level");

            bind.ConverterParameter = dataItem;
            bind.Mode      = BindingMode.OneWay;
            bind.Converter = new LevelToWidthConverter();

            Border b = new Border();

            b.BorderThickness = new Thickness(0);
            b.Background      = new SolidColorBrush(Colors.Transparent);
            b.SetBinding(Border.WidthProperty, bind);

            bind      = new Binding("Expanded");
            bind.Mode = BindingMode.TwoWay;

            SimpleExpander expander = new SimpleExpander();

            expander.Visibility         = (node.ChildNodes.Count == 0) ? Visibility.Collapsed : Visibility.Visible;
            expander.IsExpandedChanged += new EventHandler(expander_IsExpandedChanged);
            expander.SetBinding(SimpleExpander.IsExpandedProperty, bind);

            panel.Children.Add(b);
            panel.Children.Add(expander);

            return(panel);
        }
Exemplo n.º 2
0
        void ChildNode_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            IGanttNode node = sender as IGanttNode;

            if (e.PropertyName == "StartDate" || e.PropertyName == "EndDate")
            {
                UpdateDatesToChildren();
            }
        }
Exemplo n.º 3
0
        private GanttRow CreateRow(IGanttNode node)
        {
            GanttRow row = new GanttRow();

            row.BorderBrush = BorderBrush;
            row.Background  = Background;
            row.ParentPanel = this;
            row.Node        = node;
            return(row);
        }
Exemplo n.º 4
0
        int InsertChildNodes(IGanttNode node, ref  int index)
        {
            foreach (IGanttNode childNode in node.Children)
            {
                Nodes.Insert(++index, childNode);

                if (childNode.Expanded && childNode.Children.Count > 0)
                    InsertChildNodes(childNode, ref index);
            }
            return index;
        }
Exemplo n.º 5
0
        private void RemoveChildNodes(IGanttNode node)
        {
            foreach (IGanttNode childNode in node.ChildNodes)
            {
                if (childNode.ChildNodes.Count > 0)
                {
                    RemoveChildNodes(childNode);
                }

                Nodes.Remove(childNode);
            }
        }
Exemplo n.º 6
0
        private int InsertChildNodes(IGanttNode node, ref int index)
        {
            foreach (IGanttNode childNode in node.ChildNodes)
            {
                Nodes.Insert(++index, childNode);

                if (childNode.Expanded && childNode.ChildNodes.Count > 0)
                {
                    InsertChildNodes(childNode, ref index);
                }
            }
            return(index);
        }
Exemplo n.º 7
0
        protected override Size MeasureOverride(Size availableSize)
        {
            double nodeStartPosition = ParentRow.ParentPanel.ConvertDateToPosition(Section.StartDate);
            double nodeEndPosition   = ParentRow.ParentPanel.ConvertDateToPosition(Section.EndDate);

            NodeWidth = (nodeEndPosition - nodeStartPosition);

            if (NodeWidth > 0)
            {
                PercentCompleteWidth = (Node.PercentComplete / 100) * NodeWidth;
            }
            else
            {
                PercentCompleteWidth = 0;
            }

            if (GapElement != null)
            {
                GapElement.MinWidth  = 0;
                NodeElement.MaxWidth = availableSize.Width;

                if (ParentRow.RowIndex < ParentRow.ParentPanel.Nodes.Count - 1)
                {
                    IGanttNode nextNode = ParentRow.ParentPanel.Nodes[ParentRow.RowIndex + 1];
                    if (nextNode.StartDate > Node.EndDate)
                    {
                        double gapWidth = availableSize.Width - NodeWidth;

                        if (NodeWidth > 0)
                        {
                            NodeElement.MaxWidth = NodeWidth;
                        }
                        else
                        {
                            NodeElement.MaxWidth = 0;
                        }
                        if (gapWidth > 0)
                        {
                            GapElement.MinWidth = gapWidth;
                        }
                        else
                        {
                            GapElement.MinWidth = 0;
                        }
                    }
                }
            }

            return(base.MeasureOverride(availableSize));
        }
Exemplo n.º 8
0
        void GanttDataGrid_RowExpandedChanged(object sender, RowExpandedChangedEventArgs e)
        {
            IGanttNode node = (e.Row.DataContext as IGanttNode);

            node.Expanded = e.IsExpanded;

            int index = LastExpanderClickedIndex = Nodes.IndexOf(node);

            if (e.IsExpanded)
            {
                index = InsertChildNodes(node, ref index);
            }
            else
            {
                RemoveChildNodes(node);
            }

            RaiseRowExpandedChanged(e);
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
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));
        }
Exemplo n.º 11
0
        private void RemoveChildNodes(IGanttNode node)
        {
            foreach (IGanttNode childNode in node.ChildNodes)
            {
                if (childNode.ChildNodes.Count > 0)
                    RemoveChildNodes(childNode);

                Nodes.Remove(childNode);
            }
        }
 //是否存在祖父折叠的
 bool IsExistParent(IGanttNode node)
 {
     if (!node.Expanded)
         return false;
     if (node.Parent != null)
         return IsExistParent(node.Parent);
     return true;
 }
Exemplo n.º 13
0
 private GanttRow CreateRow(IGanttNode node)
 {
     GanttRow row = new GanttRow();
     row.BorderBrush = BorderBrush;
     row.Background = Background;
     row.ParentPanel = this;
     row.Node = node;
     return row;
 }
Exemplo n.º 14
0
 public GanttRow(IGanttNode node)
     : this()
 {
     this.Node = node;
 }
Exemplo n.º 15
0
 public GanttRow(IGanttNode node)
     : this()
 {
     this.Node = node;
 }