New to Telerik UI for WPF? Download free 30-day trial

Iterate Over the Diagram Items

RadDiagram provides 3 collections that store the DiagramItems - "Items", "Shapes" and "Connections"

Diagram Items Collections

Below you can see a description of the 3 collections:

  • RadDiagram.Items - inherits from Telerik.Windows.Diagrams.Core.DiagramItemCollection. The DiagramItemCollection inherits from System.Collections.ObjectModel.ObservableCollection. This mean that you are able to add everything in the Items collection. For example, if you add a Button in the Items, the ItemContainerGenerator of the RadDiagram will create a RadDiagramShape which wraps the Button and will add the generated shape in the Shapes collection.

  • RadDiagram.Shapes - inherits from Telerik.Windows.Diagrams.Core.ShapeCollection. The ShapeCollection inherits from System.Collections.ObjectModel.ReadOnlyCollection

  • RadDiagram.Connections - inherits from Telerik.Windows.Diagrams.Core.ConnectionCollection. The ConnectionCollection inherits from System.Collections.ObjectModel.ReadOnlyCollection

Iterating Over Shapes or Connections

Here you can see a possible way to iterate the Shapes or Connection of the RadDiagram:

this.diagram.Shapes.ToList().ForEach(x => 
{ 
  //your custom logic goes here 
  (x as RadDiagramShape).Content = "Shape"; 
}); 
Me.diagram.Shapes.ToList().ForEach(Function(x) 
    'your custom logic goes here' 
    TryCast(x, RadDiagramShape).Content = "Shape" 
End Function) 

Extension Methods

The RadDiagram exposes two extension methods which you can use to iterate through the incoming and outgoing connections of a shape:

  • public static IEnumerable GetOutgoingConnectionsForShape(this IGraph graph, IShape shape)

  • public static IEnumerable GetIncomingConnectionsForShape(this IGraph graph, IShape shape)

In order to take advatnage of these methods you need to add a using statement for the Telerik.Windows.Diagrams.Core namespace in your code-behind file. Then you'll be able to access both methods through a RadDiagram instance:

using Telerik.Windows.Diagrams.Core; 
... 
xDiagram.GetOutgoingConnectionsForShape(shape); 
xDiagram.GetIncomingConnectionsForShape(shape); 
Imports Telerik.Windows.Diagrams.Core 
... 
xDiagram.GetOutgoingConnectionsForShape(shape) 
xDiagram.GetIncomingConnectionsForShape(shape)         

See Also

In this article