Articles in this section
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);
  }
}

A close up of a map

Description automatically generated

View sample in GitHub.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied