I would like get some suggestions/help in implementing couple behaviours. Are there other examples in your library that implement behaviour I describe below, that I may have missed?
1) I am interested in having all racks stacked and have the ability for the racks to resize.
2) When I drag one rack over another, the rack that is on top moves up in the stacking order.
3) When I drag the Rack on the panel I would like it be left align.
4) How do I limit that nodes can only be draged onto a rack but not the canvas.
public class YComparer : IComparer<Node> {
public int Compare(Node a, Node b) {
Rect ar = a.Bounds;
Rect br = b.Bounds;
if (ar.Y < br.Y) return -1;
if (ar.Y > br.Y) return 1;
return 0;
}
}
4) Well, I’m not sure about the complete solution, but you can get a partial solution by adding a condition to the CustomDraggingTool.IsValidMember method:
public class CustomDraggingTool : DraggingTool {
public override bool IsValidMember(Group group, Node node) {
if (group == null) return false; // don't allow container Group to be null
if (node != null) {
...
The reason I think it’s incomplete is that a drop is not disallowed away from a Rack. If the user does drop in the background, the node is not re-parented from whatever Rack it had been part of before (good) but it doesn’t snap back either (bad).
Yes I can confirm the nodes are in the swimlane group. The SubgraphKey matches where I first placed it. I will try to replicate it with your code sample.
The problem was the introduction of the additional constraint that I labelled (4b) above.
Here’s a better definition of the SnapTo method:
protected override Point SnapTo(Node moving, Point pt, Node snapper, Dictionary<Part, DraggingTool.Info> draggedparts) {
// don't let a Node move outside a Group to top-level (i.e. to the background)
if (snapper == null && !(moving is Group) && this.Active) return moving.Location;
return base.SnapTo(moving, pt, snapper, draggedparts);
}