Hi,
I've a button to enable Pan mode for the diagram. When clicked the diagram's currentTool was set to the diagram's panTool. But, the problem with this was "one-time-use" i.e., once the user clicks on the diagram and releases the mouse button the currentTool is set to dragging tool. So, the user can't use the pan tool multiple times without having to click the pan button everytime.ThanksTo overcome this, I followed the below steps:
To enable Pan mode:
- Store drag & dragSelection tool to a variable
- Set diagram’s DraggingTool & DragSelectingTool to null. By doing this the pan tool can be used multiple times.
To disable Pan mode:
- Store pan tool to a variable
- Set DraggingTool & DragSelectingTool to value that was store previously
- Set PanningTool to null. This enables the selection of DraggingTool
This worked fine in WPF. But, it is not working in Silverlight. The source of error is while disabling the pan tool. When I try to assign the DraggingTool with the previously stored value, I’m getting the error “Element is already the child of another element.”
Below is the code snippet:
private void SetPanMode() { if (PanMode == true) { if (defaultDragTool == null) defaultDragTool = taskDiagram.DraggingTool; if (defaultSelectTool == null) defaultSelectTool = taskDiagram.DragSelectingTool; taskDiagram.DraggingTool = null; taskDiagram.DragSelectingTool = null; if (taskDiagram.PanningTool == null && defaultPanTool != null) taskDiagram.PanningTool = defaultPanTool; } else { if (defaultPanTool == null) defaultPanTool = taskDiagram.PanningTool; taskDiagram.DraggingTool = defaultDragTool; <font color="#FF0000"><font color="#000000">//</font><b>Source of error</b></font> taskDiagram.DragSelectingTool = defaultSelectTool; taskDiagram.PanningTool = null; } }
Version: GoWPF 1.1.3.4, GoSilverlight 1.2.6.4