コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: Forichok/Graphs
        private void MyDiagram_NodeCreated(object sender, DiagramEventArgs e)
        {
            var nodeModel = e.Part.Data as NodeModel;
            var key       = NodeKeyCreator.GetNodeName(myDiagram.Model.NodesSource.Cast <NodeModel>().Select(i => i.Key), myDiagram.Model.NodesSource.Cast <NodeModel>().Select(i => i.Key));


            nodeModel.Text = key;
            nodeModel.Key  = key;

            AddNodeToMatrix(key);
        }
コード例 #2
0
ファイル: MainViewModel.cs プロジェクト: Forichok/Graphs
        private void AddNewNode(PartManager.PartBinding sender)
        {
            try
            {
                var myDiagram = sender.Part.Diagram;
                var ad        = Part.FindAncestor <Adornment>(sender.Part.SelectionElement); //e.OriginalSource as UIElement
                if (ad == null)
                {
                    return;
                }
                // its AdornedPart should be a Node that is bound to a NodeModel object
                var from = ad.AdornedPart.Data as NodeModel;
                if (from == null)
                {
                    return;
                }
                // make all changes to the model within a transaction
                myDiagram.StartTransaction("Add NodeModel");
                // create a new NodeModel, add it to the model, and create a link from
                // the selected node data to the new node data

                var list = MainModel.NodesModelToArr(myDiagram.Model.NodesSource.Cast <NodeModel>());
                var key  = NodeKeyCreator.GetNodeName(list, Model.NodesSource.Cast <NodeModel>().Select(i => i.Key));
                var to   = new NodeModel(key);
                //  to.Text = "new";
                var p = from.Location;
                //?? this isn't a very smart way to decide where to place the node
                to.Location = new Point(p.X + 200, p.Y);
                myDiagram.Model.AddNode(to);
                var newnode = myDiagram.PartManager.FindNodeForData(to, myDiagram.Model);
                myDiagram.Select(newnode);
                EventHandler <DiagramEventArgs> show = null;
                show = (snd, evt) =>
                {
                    myDiagram.Panel.MakeVisible(newnode, Rect.Empty);
                    myDiagram.LayoutCompleted -= show;
                };
                myDiagram.LayoutCompleted += show;
                myDiagram.Model.AddLink(from, null, to, null);

                myDiagram.CommitTransaction("Add NodeModel");
            }
            catch (Exception e)
            {
                MessageBox.Show("Oops.. something goes wrong...\n\n" + e.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }