Adding hover effects on nodes in dynamically created palette


I’m using DevExpress to create a ribbon bar menu and multiple palettes are supposed to be included in it. In order to generate the palettes dynamically I’m creating a BarButtonItem in the codebehind and read a template from a xaml string that includes the palette. As it doesn’t work to include event bindings in the xaml string itself and as the DevExpress BarButtonItem is not a UIElement so I can’t use VisualTreeHelper to get hands on anything in the template to bind events to I’m using a custom behavior to add nodes to the palette dynamically.

This custom behavior is attached to the palette and in the OnAttached() function I’m adding an event handler to the TemplateApplied event so after the template is applied to the diagram I can dynamically add my nodes to the palette’s NodesSource. So far, it’s working fine. However, I need to mimic a ribbon bar gallery with the palette and thus need to add hover effects to my added nodes. I tried to add an event handler for the NodeCreated event in which I finally add event handlers for the nodes MouseEnter and MouseLeave events but contrary to the TemplateApplied one the NodeCreated event handler is never being called. What event do I have to catch to get my hands on the node that is added to the palette?

The Diagram.NodeCreated event is raised when the user creates a new node via the ClickCreatingTool. It is not raised whenever a node gets added to the diagram.

I think you want to use a custom PartManager, overriding the PartManager.OnNodeAdded method. Call the base method first, and then you can decide to establish whatever event handlers that you want on the Node or on any of its elements.

Install the custom PartManager by assigning Diagram.PartManager when you are setting up the diagram.

Working perfectly, thanks.