AvaloniaGraphControl icon indicating copy to clipboard operation
AvaloniaGraphControl copied to clipboard

Context menu for edges

Open voidray opened this issue 3 years ago • 1 comments

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.

voidray avatar Feb 15 '22 14:02 voidray

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...)

Oaz avatar Apr 05 '22 19:04 Oaz