Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Assigned ContextMenu do not work for nodes, links and the diagram itself (Read 539 times)
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Assigned ContextMenu do not work for nodes, links and the diagram itself
Mar 25th, 2024 at 9:48am
Print Post  
Hi,

Previously, I assigned a context menu to the diagram items. Probably, after updating to version 4, it would be possible to assign the diagram context menu to DiagramView, like some other properties now. But what about other elements? How can I make their context menus, assigned as node.ContextMenu and link.ContextMenu, work again?

Please see the attached test project. There a context menu is created for all elements of the diagram but doesn't work.

Thanks,
Kostya
  

MindFusion_v4_context_menu_issue.rar ( 1121 KB | 14 Downloads )
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Assigned ContextMenu do not work for nodes, links and the diagram itself
Reply #1 - Mar 25th, 2024 at 11:49am
Print Post  
Hi,

That seems derived from FrameworkElement, and I'm not sure our developers ever realized it's there, seeing that sample projects show menu instance from NodeClicked event handler instead of relying on the property. For time being you could show your menus from NodeClicked or LinkClicked too, e.g.:

Code
Select All
private void siteMap_NodeClicked(object sender, MindFusion.Diagramming.Wpf.NodeEventArgs e)
{
	// we handle only right-clicks
	if (e.MouseButton != MouseButton.Right)
		return;

	if (!(e.Node is ShapeNode))
		return;

	// save the node reference
	currentNode = e.Node as ShapeNode;

	// display context menu for the node
	ContextMenu cmNode = createNodeMenu();
	cmNode.Placement = System.Windows.Controls.Primitives.PlacementMode.Mouse;
	cmNode.IsOpen = true;
} 



We'll have in mind restoring support for the WPF's menu property for next release.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Re: Assigned ContextMenu do not work for nodes, links and the diagram itself
Reply #2 - Mar 26th, 2024 at 10:31am
Print Post  
Hi Slavcho,

Got it, thanks. Can you please tell me the approximate timing of the next release, and can we expect that this feature will be restored there? To decide whether to use a workaround now or wait.

Thanks,
Kostya
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Assigned ContextMenu do not work for nodes, links and the diagram itself
Reply #3 - Mar 27th, 2024 at 9:36am
Print Post  
Hi Kostya,

Please check if this build works for you, it binds NodePresenter.ContextMenu to the node's property -
https://mindfusion.eu/_beta/wpfdiag409.zip

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Re: Assigned ContextMenu do not work for nodes, links and the diagram itself
Reply #4 - Mar 27th, 2024 at 11:03am
Print Post  
Hi Slavcho,

This works for nodes, thanks! Let me clarify about the context menu of the diagram itself. Can we expect this to work too?

Btw, looks like events like ContextMenuOpening do not work for nodes & links.

Kostya
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Assigned ContextMenu do not work for nodes, links and the diagram itself
Reply #5 - Mar 28th, 2024 at 12:53pm
Print Post  
Hi Kostya,

Conclusion of version 4' model/view separation is that we'll remove Diagram's base class (Control) from version 5 release, so it will lose the inherited menu property too. Check if DiagramView.ContextMenu couldn't serve as direct replacement of diagram's one for you.

DiagramItem's base FrameworkElement will be removed too along with inherited ContextMenuOpening event. We'll add item-menu-opening events to Diagram class for the v4.0.9 release, which you could handle instead, also to better match the other node/link events from the API.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Re: Assigned ContextMenu do not work for nodes, links and the diagram itself
Reply #6 - Mar 28th, 2024 at 5:05pm
Print Post  
Thanks for the info, Slavcho! I'll be waiting for the new release 👌 And yes, using DiagramView.ContextMenu sounds good.

Kostya
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Assigned ContextMenu do not work for nodes, links and the diagram itself
Reply #7 - Apr 1st, 2024 at 10:00am
Print Post  
Hi Kostya,

Please try NodeMenuOpening and LinkMenuOpening events from this build -
https://mindfusion.eu/_beta/wpfdiag409.zip

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Re: Assigned ContextMenu do not work for nodes, links and the diagram itself
Reply #8 - Apr 5th, 2024 at 9:05pm
Print Post  
Hi Slavcho,

Thank you! Now the context menus of diagram elements work and the events preceding them work too.

The only problem is that the links are too thin to work comfortably with their context menus, you need to aim. I already received an answer on the forum that a workaround could be to use the Click event, which takes into account the LinkHitDistance and this works well. But then this defeats the purpose of the context menu. Can you please tell me if there is a way to take into account the LinkHitDistance value in case of context menu now or in the future? That is, without Click and with the working LinkMenuOpening event.

Thanks,
Kostya
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Assigned ContextMenu do not work for nodes, links and the diagram itself
Reply #9 - Apr 9th, 2024 at 8:29am
Print Post  
Hi Kostya,

New build here should honor LinkHitDistance for showing DiagramLink's menu -
https://mindfusion.eu/_beta/wpfdiag409.zip

Since we are now doing custom hit-testing and menu handling for that, we've also restored Diagram.ContextMenu functionality, showing it when no diagram items are found under mouse pointer. If Diagram.ContextMenu is null, WPF's default handler should still show DiagramView's menu.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Re: Assigned ContextMenu do not work for nodes, links and the diagram itself
Reply #10 - Apr 9th, 2024 at 11:48am
Print Post  
Hi Slavcho,

Thanks, both of these improvements are really cool! Could you please note that when displaying a context menu taking into account LinkHitDistance, its PlacementTarget is not assigned? The thing is that in the context menu item handlers I find the parent diagram element like this

Code
Select All
((ItemRenderer)contextMenu.PlacementTarget).Item; 



Probably, it would be possible to find the element on LinkMenuOpening. But since the ContextMenu.PlacementTarget way works fine for any other elements, it would be nice to be able to use it in this case too.

Best regards,
Kostya
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Assigned ContextMenu do not work for nodes, links and the diagram itself
Reply #11 - Apr 10th, 2024 at 7:09am
Print Post  
Hi Kostya,

The ItemRenderer cast won't work for nodes with custom templates, so we've decided to set attached DiagramItem property on the menu as official API. Please try code below with new build:

Code
Select All
var diagramItem = Diagram.GetDiagramItem(contextMenu); 


https://mindfusion.eu/_beta/wpfdiag409.zip

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Re: Assigned ContextMenu do not work for nodes, links and the diagram itself
Reply #12 - Apr 10th, 2024 at 1:04pm
Print Post  
Hi Slavcho,

Thanks, I really appreciate you making all these improvements so quickly! All context menus used in the diagram work well now Smiley

Best regards,
Kostya
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint