This blog post shows how to dump the visual tree into a console window, using F#.
In my continued quest to understand how F# and WPF can work well together, I wrote a simple utility which walks down the visual tree of a UI and writes it out to a console window. I found that F# is a natural fit for this type of quick script-like coding. This app is not imminently useful, but it is a great way to both learn F# and get used to manipulating WPF with F#.
Here is the F# code:
Notice in the ‘createWindow’ function it uses the ‘use’ keyword. That is a relatively new addition to the language, which you can read more about here. It’s like a ‘using’ block in C#.
When the app runs, it loads a Window from a XAML file. That XAML looks like this:
When you run the app, you will see both a console window and the window which was loaded from the XAML file. Here is a screenshot: