How to add a count number after a node collapsed

Hi, I want to detect a collapsed state of a node , and add the children number on the node after I click the expand button. Can you help? Thank you very much.


Node.isTreeExpanded is property the property you are looking for.

You’ll have to add a Panel holding a Shape and a TextBlock and set its TextBlock.text to the value of Math.floor(node.findTreeParts().count/2). Whenever the tree structure changes, you’ll need to update all of the affected TextBlocks.

Thank you very much for your quick reply , I have something I am not sure. When I add a Panel, I am doing this:

When I bind the isVisible property, I want to know if it’s expanded or not. But isTreeExpanded is a property of Node, should I need to use setDataProperty to change my model? Or is there a quick api to get the Node.isTreeExpanded directly here?

Sorry, but I do not think you can use a data binding conversion function as the way to set the text to the correct value. Your code will have to compute and set all affected values, either directly on the TextBlock or on a data property with a simple binding, depending on whether the information should be in the model or not.

The scope of a data binding is the Part and its bound data. A change in another Part or in a different data object will not be automatically computed/derived/updated. In your situation adding or modifying or removing a Link will affect the desired values of many different Nodes that might be “far” away from the Link.