Get key of collapsed Subgraph from which link goes out

Hi, How I can define Subgraph key from which the link (from default subgraph port) goes out. Depending on expanded subgraph in subgraph hierarchy this key can be different. The link is connecting two nodes located in two different subgraph hierarchies. In other word I want to keep/load as many versions of link route points as diagram may have. In my solution the link should have main FromNode ТоNode definition (nodes), but definetly I should be able to get current From То definitions if links come from subgraph.

Starting with the Link’s FromNode or ToNode itself, find the first Node that is Visible by traversing the ContainingSubGraph chain of Groups.

That Node.Data’s key is what I think you are looking for.

EDIT: here’s some code:

    // return this Node if it's visible,
    // otherwise the first containing Group that is visible,
    // or else null
    Node FindVisibleNode(Node n) {
      while (n != null && n.Visibility != Visibility.Visible) {
        n = n.ContainingSubGraph;
      return n;

Thanks for this, Walter, сode looks very fine(concisely)