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); }
void ChildNode_PropertyChanged(object sender, PropertyChangedEventArgs e) { IGanttNode node = sender as IGanttNode; if (e.PropertyName == "StartDate" || e.PropertyName == "EndDate") { UpdateDatesToChildren(); } }
private GanttRow CreateRow(IGanttNode node) { GanttRow row = new GanttRow(); row.BorderBrush = BorderBrush; row.Background = Background; row.ParentPanel = this; row.Node = node; return(row); }
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; }
private void RemoveChildNodes(IGanttNode node) { foreach (IGanttNode childNode in node.ChildNodes) { if (childNode.ChildNodes.Count > 0) { RemoveChildNodes(childNode); } Nodes.Remove(childNode); } }
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); }
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)); }
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); }
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)); }
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)); }
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; }
private GanttRow CreateRow(IGanttNode node) { GanttRow row = new GanttRow(); row.BorderBrush = BorderBrush; row.Background = Background; row.ParentPanel = this; row.Node = node; return row; }
public GanttRow(IGanttNode node) : this() { this.Node = node; }
public GanttRow(IGanttNode node) : this() { this.Node = node; }