It seems that a bug has slipped into the ToggleChildrenVisibilityRecursively method.
Indeed, this method doesn't take into account the property AreChildrenVisible value of the connection target. So even if a shape is declared as collapsed, when a shape parent is expanded, this child shape is also expanded. Unfortunately, the togglebutton doesn't indicate this state.
Below, a proposed solution :
ToggleChildrenVisibilityRecursively(Visibility nextVisibility, IShape shape)
connection.Visibility = nextVisibility;
(!shape.Equals(connection.Target) && connection.Target !=
connection.Target.Visibility = nextVisibility;
var l_mindshapeTarget = connection.Target
(nextVisibility == System.Windows.Visibility.Visible && l_mindshapeTarget !=
Keep up the good work