There is currently no straightforward way of doing what you are suggesting...
An alternative approach would be to implement your TreeNav class as a subtemplate which could be generated within something like the MetaControl or something like that. That way, the code for the TreeNav class will only show up if your condition holds true.