Changing selectionObject dynamically?


I have a node deriving from GoSubGraph. When the node is expanded, I want the selectionObject to be the node itself, when it is collapsed, I want it to be the CollapsedObject.

I tried the naive:

public override GoObject SelectionObject { get { if (IsExpanded) { return this; } else { return CollapsedObject; } } }

But in collapsed mode, my object is surrounded with an ever-present blue rectangle. This rectangle does not appear if I allways set SelectionObject to CollapsedObject (but of course, the selection is wrong in expanded mode). If I start in collapsed mode, the rectangle does not appear before I do an expand/collapse.

I tried to replace IsExpanded with variations arround State==Expanding, State==Expanded and combinations thereof, but with no success.

Is there something I missed ?

By the way, when my application is starting, if I do not explicitely call Collapse() or Expand(), the subgraph is in a state that is neither collapsed nor expanded. Is this normal ?

Thank you,

I bet you only see the problem when the subgraph is selected.
The issue is dynamically changing the SelectionObject while the node is selected. The view does not realize that the SelectionObject for the selected subgraph becomes a different object when the subgraph is collapsed, and that it changes again when the subgraph is expanded. So the view does not update the selection handle(s).
Note the comment in the documentation:

I’m not sure about the best way to get around this problem. Maybe you could override Collapse() and/or Expand() to toggle the GoObject.Visible property twice. Changing the visibility of an object will cause each GoView to call AddSelectionHandles again.
The default GoSubGraph.State is GoSubGraphState.Expanded, so by default IsExpanded should be true.