How can I control object manager collapse or expand

I want to create a button to control object manager.

The function is collapse/expand all my pages, layers and shapes.

How can I use C# to do it?