Ayende @ Rahien

It's a girl

How to find the stack trace for data binding?

This is a rather special request, I’ll admit. For reasons of my own, I need to find the method(s) called to actually performed data binding in WPF & WinForms.

I have an elegant solution, which is too large to include in this blog post, but I’ll say that it doesn’t involves reflector at all.

Can you figure it out?

Comments

configurator
09/23/2010 10:12 AM by
configurator

Throwing an exception and looking at its stack trace?

Andres
09/23/2010 10:13 AM by
Andres

Dynamics?

Paulo Quicoli
09/23/2010 10:47 AM by
Paulo Quicoli

Maybe, using some AOP you can log those methods for further use.

Harry M
09/23/2010 11:03 AM by
Harry M

I have discovered a truly marvelous method to find the methods used in databinding, in WPF or Winforms. This margin is too narrow to contain it.

Lars Hundertwasser
09/23/2010 11:22 AM by
Lars Hundertwasser

This sounds like "Fermat's Last Theorem" :). Sure hope the outcome will be different.

Hugo
09/23/2010 11:24 AM by
Hugo

Use a "debug" converter, which does nothing but return the value passed in, and set a breakpoint in the "Convert" method?

Samuel Jack
09/23/2010 11:48 AM by
Samuel Jack

Put breakpoints in the get and set methods of properties that are databound, then look at the stack trace in Visual Studio.

For bonus points, enable .Net Framework source stepping and you can step through the databinding engine.

Alex Simkin
09/23/2010 12:57 PM by
Alex Simkin

@Samuel Jack Yep. That's how I do it too.

Daniel Hoelbling
09/23/2010 03:26 PM by
Daniel Hoelbling

Dynamic Proxy Interceptor with a Breakpoint in it? ;)

greetings Daniel

Leon Breedt
09/23/2010 09:26 PM by
Leon Breedt

Trace points and printing of $CALLSTACK?

Dathan
09/24/2010 02:57 PM by
Dathan

Two of my three approaches were already mentioned above:

1) Breakpoint in the property getter/setter;

2) Throw an exception in the property getter/setter;

Also, you could use the profiling API, but I don't think that counts as an "elegant solution."

For WinForms, you could probably also attach Format and/or Parse listeners to the Binding, and break/throw inside the appropriate methods. There's no guarantee that the call to Format/Parse is going to be made within the specific call stack that you're hoping to find, though.

Comments have been closed on this topic.