Is there a way to tell where an event was raised from?
I've got an event that's firing more times than I thought it should fire. Is there any way to tell where an event was raised from?
The event is DataContextChanged for a ComboBox. All I need is basic data on what caused the event to fire... any way to do it?
Re: Is there a way to tell where an event was raised from?
Yes, the sender argument of all event handlers keeps a reference to the object that raised the event.
Re: Is there a way to tell where an event was raised from?
Yeah, I checked that first. They all point back to the combo box itself... and since I know for a fact that at least one of the events is fired via code, manually setting the SelectedIndex value... well, that means that it doesn't really differentiate between code and user action.
Re: Is there a way to tell where an event was raised from?
Could you not set a breakpoint on the event handler and, when hit, examine the call stack? I think that any code that is causing the event will show up that way.
Re: Is there a way to tell where an event was raised from?
You you've solved the problem I take it?
[EDIT]
Inferred posted while I was making mine.
My question was in response to your last post:-
Quote:
Yeah, I checked that first. They all point back to the combo box itself... and since I know for a fact that at least one of the events is fired via code, manually setting the SelectedIndex value... well, that means that it doesn't really differentiate between code and user action.
I'm not certain what you are trying to say here.
Re: Is there a way to tell where an event was raised from?
There isn't necessarily a way to determine what caused the event to trigger, just who triggered it. Examining the call stack at the time of the event can tell you some things, but it may not tell you what you want to know. MSDN might also give you some information as to what actions can trigger certain events, but aside from that you can probably work it out just by testing things.