Activate custom ClickCreatingTool on button click


I have a diagram with various palettes from which I place nodes. However, if the user clicks a certain button, my custom ClickCreatingTool is supposed to be enabled while the palettes get disabled.

When I set my ClickCreatingTool during diagram initialization, it works. However, when I set the ClickCreatingTool to null at first, and set the actual tool afterwards in an event handler, it simply gets ignored.

I had a similar issue with the DragSelectingTool, which I could only (de)activate if I also (de)activated the DraggingTool. However, that one is set during initialization and later on set to null.

So, is there another tool that interferes with the usage of the ClickCreatingTool, that gets set if the ClickCreatingTool has been set to null? How can I get the ClickCreatingTool to work if set after initialization?

It would be easiest to set Tool IsEnabled to false or true, when needed.

I have set IsEnabled to false but the tool still gets triggered.

Oops, I’m sorry, I meant setting or binding DiagramTool.MouseEnabled, not FrameworkElement.IsEnabled.

Still gets triggered with MouseEnabled set to false.

You aren’t setting Diagram.CurrentTool to the tool that you don’t want to run, are you? Because as long as you are not doing so, the ToolManager always calls IDiagramTool.CanStart on each tool that it manages to see if it is eligible to be started by making it the CurrentTool.

And each tool’s implementation of CanStart calls the base method, DiagramTool.CanStart, which is implemented as:

    public virtual bool CanStart() { 
      return this.MouseEnabled;

So I do not see how the ClickCreatingTool could possibly be started by the ToolManager as long as its MouseEnabled property is false.

Unless maybe you overrode the CanStart method not to check for MouseEnabled?

The tool is supposed to create a specific node upon clicking on another specific node. As CanStart calls FindPartAt and only returns true if no part has been found I had to override it indeed. I am now checking additionally for MouseEnabled and Model.Modifyiable as the CanStart usually does according to documentation. It works now, thanks :)