How to get expected height of a TreeView?

I want to put a TreeView inside a ViewPort, so TreeView should been set with its “naturally” expanding height. However, as TreeView items could have variable show/hide states and heights (and possibly margins), how could I get the summed-up height of all items in simple way?