We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Model.AppendChild vs Controller.ExecuteCommand(insCmd)

I wish to add a symbol to a diagram programmatically. It appears that both the following alternatives achieve the same thing, with the exception that AppendChild requires DiagramRefresh() to be called. Are there any significant differences between these two approaches? What is the recommended approach from syncfusion? //Append Child variant SymbolPalette palette = paletteGroupBar.GetPalette(0); CustomSymbolModel symbolModel = palette.GetChild(0) as CustomSymbolModel; Symbol newSymbol = symbolModel.CreateSymbol(); newSymbol.X = 20; newSymbol.Y = 40; diagram.Controller.Model.AppendChild(newSymbol); //A refresh is needed before the new symbol appears. diagram.Refresh(); //Execute command variant SymbolPalette palette = paletteGroupBar.GetPalette(0); CustomSymbolModel symbolModel = palette.GetChild(0) as CustomSymbolModel; Symbol newSymbol = symbolModel.CreateSymbol(); NodeCollection nodes = new NodeCollection(); nodes.Add(newSymbol); InsertNodesCmd insCmd = new InsertNodesCmd(); insCmd.Location = new Point(30, 50); insCmd.Nodes.Concat(nodes); diagram.Controller.ExecuteCommand(insCmd);

2 Replies

AD Administrator Syncfusion Team June 20, 2005 02:12 PM UTC

I''m thinking that the difference is with ExecuteCommand you have the ability to undo, while you can''t with AppendChild :)


AD Administrator Syncfusion Team June 21, 2005 02:55 PM UTC

As Kevin pointed out, using the Essential Diagram Command classes through the Controller will append the executed command to the diagram''s undo/redo stack providing you with the ability to undo the operation if necessary. Regards, Prakash Surendra Syncfusion Inc.,

Loader.
Live Chat Icon For mobile
Up arrow icon