Category / Section
How to get or set the positions of the segments by programmatically in WPF Diagram (SfDiagram)?
1 min read
The ToPoints() and LoadSegments() methods of the IConnectorInfo can be used to retrieve and update the positions of the connector segments respectively in WPF Diagram (SfDiagram).
XAML
<Grid> <syncfusion:SfDiagram x:Name="diagram" PortVisibility="Visible"/> <Button x:Name="LoadSegment" Height="50" Width="80" HorizontalAlignment="Left" VerticalAlignment="Top" Click="LoadSegment_Click" Content="Load Segments"/> </Grid>
C#
public partial class MainWindow : Window { IEnumerable<Point> segmentpoints; ConnectorViewModel connector; public MainWindow() { InitializeComponent(); diagram.Connectors = new ConnectorCollection(); connector = new ConnectorViewModel() { SourcePoint = new Point(400, 400), TargetPoint = new Point(800, 200), }; (diagram.Connectors as ConnectorCollection).Add(connector); (diagram.Info as IGraphInfo).ConnectorEditing += MainWindow_ConnectorEditing; } private void MainWindow_ConnectorEditing(object sender, ConnectorEditingEventArgs args) { if (args.Item is ConnectorViewModel) { segmentpoints = ((args.Item as ConnectorViewModel).Info as IConnectorInfo).ToPoints(); } } private void LoadSegment_Click(object sender, RoutedEventArgs e) { segmentpoints = new List<Point>() { new Point(20, 20), new Point(30, 30) }; (connector.Info as IConnectorInfo).LoadSegments(segmentpoints); } }