Context menu for edges
I would like to add a context menu to remove edges. I'm not sure if it is the best way, but I added this to the GraphPanel:
<agc:GraphPanel.DataTemplates>
<DataTemplate DataType="{x:Type agc:Edge}">
<agc:Connection>
<agc:Connection.ContextMenu>
<ContextMenu>
<MenuItem Command="{Binding $parent.DataContext.RemoveEdge}" CommandParameter="{Binding}" Header="Remove edge"/>
</ContextMenu>
</agc:Connection.ContextMenu>
</agc:Connection>
</DataTemplate>
</agc:GraphPanel.DataTemplates>
The binding to a method works if I use the code behind and Click="MyMethod", but how do I bind to a view model method (with the xaml above, the context menu item is disabled)? When I use Command="{Binding RemoveEdge}", the menu item is enabled, but the viewmodel method doesn't get called.
I need to pass the edge somehow as parameter. With the code behind approach the Edge is the DataContext property of MenuItem (which is the sender:
public void MyMethod(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
}
Another question is if it is possible to specify the thickness of the connection line? I only saw a Brush property. Since the line is pretty thin it would be helpful to make it a bit thicker on hover.
I don't know how ContextMenus work. So, for now, I'm afraid I cannot help on this.
Regarding the thickness of the connection line, the Connection class could indeed be improved with additional drawing attributes (thickness, dash style...)