Displacement of Node when context menu is displayed

Hi,

I have created a context menu for the right click on the node. When the context menu is displayed and I click on the diagram without selecting the context menu option, the selected node is moved to the clicked location.

Please find the attached GIF, I have made a similar code change in the GoXam sample.

com-video-to-gif%20(2)

That’s interesting. I don’t get that behavior in the GoWpfBasic sample app, which implements context menus on nodes.

How did you implement your context menu? Have you customized the DraggingTool at all?

In our application we have provided some functionalities for the nodes (like flip, rotate, customized dialogus, etc…), for using the functionalities we have introduced the context menu items which on selection would trigger the feature.

Currently, I am using the WPF Context menu object, which will be shown when the user right clicks on the Node.

Could you please elaborate on the dragging tool’s customization

In our samples, for context menus we have something like this in the node template:

  <ContextMenuService.ContextMenu>
    <ContextMenu>
      <MenuItem Header="some command" Click="Some_Click" />
    </ContextMenu>
  </ContextMenuService.ContextMenu>

with the code:

    private void Some_Click(object sender, RoutedEventArgs e) {
      var elt = sender as FrameworkElement;
      if (elt != null && elt.DataContext != null) {
        myDiagram.StartTransaction("Some Command");
        . . .
        myDiagram.CommitTransaction("Some Command");
      }
    }
  }

Is yours differently implemented, other than the actual command details, of course?

Below attached code is the only code change done in the DraggableLink class in the samples.

//Added this line in the constructor
myDiagram.MouseRightButtonDown += MyDiagram_MouseRightButtonDown;

//handler for the same
private void MyDiagram_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
ContextMenu menu = new ContextMenu();
menu.Items.Add(“one”);
menu.Items.Add(“two”);
menu.Items.Add(“three”);
menu.IsOpen = true;
}

I haven’t tried your code yet, but you at least need to mark the event as Handled so that other event handlers (such as those of GoXam) don’t do anything.

And I’m concerned that your implementing context menus that way has other deficiencies that you need to implement. I don’t know what those might be. That’s why I would recommend using the standard facilities instead if rolling your own.