示例#1
0
        private void NodeExpanded(DiagramNode sender, RoutedEventArgs eventArguments)
        {
            rootNode.Location = new Point(
                (double)GetValue(Canvas.ActualWidthProperty) / 2.0,
                (double)GetValue(Canvas.ActualHeightProperty) / 2.0);


            MakeChildrenVisible(sender);

            if (sender.DiagramParent != null)
            {
                sender.DiagramParent.Visibility = Visibility.Visible;
                foreach (DiagramNode sibling in sender.DiagramParent.DiagramChildren)
                {
                    if (sibling != sender)
                    {
                        sibling.Visibility = Visibility.Collapsed;
                    }
                }
                if (sender.DiagramParent.DiagramParent != null)
                {
                    sender.DiagramParent.DiagramParent.Visibility = Visibility.Collapsed;
                }
            }

            if (sender.DiagramChildren.Count > 0)
            {
                double startAngle           = CalculateStartAngle(sender);
                double angleBetweenChildren = (sender == rootNode ? Math.PI * 2.0 : Math.PI) / ((double)sender.DiagramChildren.Count - 0);

                double legDistance = CalculateLegDistance(sender, angleBetweenChildren);

                for (int i = 0; i < sender.DiagramChildren.Count; ++i)
                {
                    DiagramNode child = sender.DiagramChildren[i];
                    child.Selected  += new NodeStateChangedHandler(NodeSelected);
                    child.Expanded  += new NodeStateChangedHandler(NodeExpanded);
                    child.Collapsed += new NodeStateChangedHandler(NodeCollapsed);

                    Point parentLocation = sender.Location;

                    child.Location = new Point(
                        parentLocation.X + Math.Cos(startAngle + angleBetweenChildren * (double)i) * legDistance,
                        parentLocation.Y + Math.Sin(startAngle + angleBetweenChildren * (double)i) * legDistance);

                    foreach (DiagramNode childsChild in child.DiagramChildren)
                    {
                        childsChild.Visibility = Visibility.Collapsed;
                    }
                }
            }

            BaseCanvas.InvalidateArrange();
            BaseCanvas.UpdateLayout();
            BaseCanvas.InvalidateVisual();
        }
示例#2
0
 private void NodeCollapsed(DiagramNode sender, RoutedEventArgs eventArguments)
 {
     foreach (DiagramNode child in sender.DiagramChildren)
     {
         child.Visibility = Visibility.Collapsed;
         foreach (DiagramNode grandChildren in child.DiagramChildren)
         {
             grandChildren.Visibility = Visibility.Collapsed;
         }
     }
     BaseCanvas.InvalidateArrange();
     BaseCanvas.UpdateLayout();
     BaseCanvas.InvalidateVisual();
 }
示例#3
0
        private void MakeChildrenVisible(DiagramNode sender)
        {
            foreach (DiagramNode child in sender.DiagramChildren)
            {
                if (!BaseCanvas.Children.Contains(child))
                {
                    BaseCanvas.Children.Add(child);
                }
                else
                {
                    child.Visibility = Visibility.Visible;
                }
            }

            BaseCanvas.InvalidateArrange();
            BaseCanvas.UpdateLayout();
            BaseCanvas.InvalidateVisual();
        }