Spying on Your WPF Applications with Snoop

If you’re developing WPF applications and do not have Snoop installed; install it now. I’ll wait. Installed? Good.

Snoop is an open source tool for spying and debugging a running WPF application. It can be used to inspect your running application and make changes while your app is still running. I’ve found it to be very useful for finding missing bindings and tweaking layout parameters when you can’t use Designer. (don’t ask, that’s a blog post for another day.)

Here are a few tips to get you started:

Selecting Your App

After installing and launching Snoop, drag the cross-hairs from the Snoop window to your WPF application. You’ll see your application tree on the left and a property editor on the right for whatever component you have selected.

Snoop app selector

Find Your Widget

An easy way to find the widget you want to work with is to use the ctrl-shift mouseover trick. Simple press ctrl-shift and hover around your app. Elements of your app will highlight with a red border. Once you’ve found your widget, simple release the keys and your item will remain selected for modification in Snoop.

Snoop main view

Filter Properties

Finding the properties you’re interested in can be cumbersome. The first TextBlock I inspected have well over 100 properties. There is a quick search filter at the top of the property editor, but I like to see all the layout related properties at once. Snoop has a shortcut for this: select “Layout” from the filter drop-down to see only layout related properties (Width, Height, Margin, Padding, etc). Find your property, click, make change, see change. Nice and simple.

Finding Data Binding Problems

A lesser-known feature of Snoop is its ability to identify data binding problems. When seeing if a component is bound correctly, I usually just try it and see if it works. If it doesn’t, I turn to the noisy output of Visual Studios debug output. No more. If I don’t see the value right away, I attach Snoop to my app and select the “Show only visuals with binding errors” option from the search/filter bar above the application tree view. It will list out only the problematic components. Another win for Snoop!

Snoop has served me well and should be used by anyone developing WPF applications.
 

Conversation
  • Assassin says:

    Nice article!!
    BTW can we make our application snoop-proof.

    • Shawn Anderson Shawn Anderson says:

      Thanks! I’m glad you liked it. As for making an app snoop-proof, I have not thought about that. I don’t know of anyway of doing that off the top of my head. If you find one, please post it back here.

  • Comments are closed.