Category / Section
How to update the Zindex of the dragged node in WPF Diagram (SfDiagram)?
1 min read
Currently, the ZIndex of a Node depends on the order when the node is added. You can interactively update a ZIndex of the Node independent in which order it has added. Here, you can see the ZIndex of a Node updated while dragging using the NodeChangedEvent of WPF Diagram (SfDiagram) class.
C#
SfDiagram diagram = new SfDiagram(); //The event will get hooked whenever interact with the node. (diagram.Info as IGraphInfo).NodeChangedEvent += MainWindow_NodeChangedEvent; private void MainWindow_NodeChangedEvent(object sender, ChangeEventArgs<object, NodeChangedEventArgs> args) { var draggednode = args.Item as NodeViewModel; if (args.NewValue.InteractionState == NodeChangedInteractionState.Dragging) { if (draggednode.ZIndex != int.MaxValue) { OldNodeZindex = draggednode.ZIndex; } //Updating the maximum ZIndex to the dragging element. draggednode.ZIndex = int.MaxValue; } else if(args.NewValue.InteractionState == NodeChangedInteractionState.Dragged) { //Resetting the ZIndex to the actual value. draggednode.ZIndex = OldNodeZindex; } }