Пример #1
0
        public SerialRelation Serialize()
        {
            SerialRelation serial = new SerialRelation
            {
                Parent       = parent.ID,
                Child        = child.ID,
                ParentAnchor = parentAnchor.Name,
                ChildAnchor  = childAnchor.Name
            };

            return(serial);
        }
Пример #2
0
        public Relation(SerialRelation serial)
        {
            foreach (Node node in MDiagram.Nodes)
            {
                if (node.ID == serial.Parent)
                {
                    parent = node;
                }
                else if (node.ID == serial.Child)
                {
                    child = node;
                }
            }

            foreach (Anchor anchor in parent.Anchors)
            {
                if (anchor.Name == serial.ParentAnchor)
                {
                    parentAnchor = anchor;
                }
            }

            foreach (Anchor anchor in child.Anchors)
            {
                if (anchor.Name == serial.ChildAnchor)
                {
                    childAnchor = anchor;
                }
            }
            child.AddParent(parent, false);
            parent.AddChild(child);

            this.ArrowEnds       = ArrowEnds.End;
            this.IsArrowClosed   = true;
            this.Stroke          = Brushes.Blue;
            this.StrokeThickness = 3;

            ContextMenu contextMenu = new ContextMenu();

            tryTurn           = new MenuItem();
            tryTurn.Header    = "Try Turning";
            tryTurn.Click    += TryTurning;
            tryTurn.IsEnabled = MDiagram.Evaluating;
            contextMenu.Items.Add(tryTurn);
            deleteItem        = new MenuItem();
            deleteItem.Header = "Remove";
            deleteItem.Click += DeleteItem_Click;
            contextMenu.Items.Add(deleteItem);
            this.ContextMenu = contextMenu;

            this.SetBinding(ArrowLine.X1Property, new Binding()
            {
                Source = parentAnchor,
                Path   = new PropertyPath(Anchor.AnchorX1Property)
            });
            this.SetBinding(ArrowLine.Y1Property, new Binding()
            {
                Source = parentAnchor,
                Path   = new PropertyPath(Anchor.AnchorY1Property)
            });
            this.SetBinding(ArrowLine.X2Property, new Binding()
            {
                Source = childAnchor,
                Path   = new PropertyPath(Anchor.AnchorX1Property)
            });
            this.SetBinding(ArrowLine.Y2Property, new Binding()
            {
                Source = childAnchor,
                Path   = new PropertyPath(Anchor.AnchorY1Property)
            });

            MainWindow.GetCanvas.Children.Add(this);
            MDiagram.AddRelation(this);
        }