I want to draw lines connecting blocks which are drawn by ItemsControl. These are my classes:
public class NodeBase
{
public string Name { get; set; }
public double X { get; set; }
public double Y { get; set; }
public List<Connector> Inputs { get; set; }
public List<Connector> Outputs { get; set; }
}
public class Connector
{
public string Name { get; set; }
public List<Connection> Connections { get; set; }
}
public class Connection
{
public NodeBase TargetBlock { get; set; }
}
Then I have List which I set as ItemsControls ItemsSource.
This is my DataTemplate for each NodeBase item:
<DataTemplate DataType="{x:Type local:NodeBase}">
<Border BorderBrush="Black" BorderThickness="1">
<StackPanel>
<DockPanel>
<TextBlock Text="{Binding Name}" TextAlignment="Center" Foreground="White" Margin="30, 0, 30, 0" DockPanel.Dock="Top"/>
<Grid Background="Gray">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*"/>
<ColumnDefinition Width="50*"/>
</Grid.ColumnDefinitions>
<local:InputItemsControl ItemsSource="{Binding Inputs}" Grid.Column="0"/>
<local:OutputItemsControl ItemsSource="{Binding Outputs}" Grid.Column="1" Margin="5, 0, 0, 0"/>
</Grid>
</DockPanel>
</StackPanel>
</Border>
</DataTemplate>
OutputItemsControl and InputItemsControl are ItemsControls. DataTemplate for Connectors in OutputItemsControl looks like this:
<DataTemplate DataType="{x:Type local:Connector}">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock Text="{Binding Name}" HorizontalAlignment="Right"/>
<Rectangle Fill="Black" Width="5" Height="5" HorizontalAlignment="Right" Margin="5, 0, 0, 0" Name="_ConnectorRectangle"/>
</StackPanel>
</DataTemplate>
My blocks are drawn correctly. Now I want to draw a Line between rectangles named "_ConnectorRectangle" to connect the visual node representations. Any ideas how can I achieve it?