Category / Section
How to restrict the child node dragging whereas allow group dragging in WPF Diagram (SfDiagram)?
1 min read
The Groups and Nodes can be dragged on the WPF Diagram (SfDiagram) page by default. By using the Constraints property of Group and Node, groups can be dragged whereas nodes that are child elements of a group could not be dragged.
C#
SfDiagram diagram = new SfDiagram(); (diagram.Info as IGraphInfo).ItemSelectedEvent += MainWindow_ItemSelectedEvent; private void MainWindow_ItemSelectedEvent(object sender, DiagramEventArgs args) { if ((args as ItemSelectedEventArgs).Item is IGroup) { foreach (var item in (((args as ItemSelectedEventArgs).Item as IGroup).Nodes) as ObservableCollection<NodeViewModel>) { (item as INode).Constraints = NodeConstraints.Default; } } else if ((args as ItemSelectedEventArgs).Item is INode) { ((args as ItemSelectedEventArgs).Item as INode).Constraints = NodeConstraints.Default & ~(NodeConstraints.Draggable | NodeConstraints.InheritDraggable); } }