views:

68

answers:

2

I am trying to determine what control called a Set property. Say textbox Pet is bound to a Property. I am using INotifyPropertyChanged but I am wondering if there is a way to get the actual control.

The sender in my PropertyChanged Event is the Class containing the properties and not the control that originally kicked of the chain of events that lead to the Event being raised.

Is this possible? Is there an easier way?

A: 

If you need to know which control did something, just attach an event to the control and handle that event in the view's codebehind.

The INPC model object that's having bindings applied to it should be view-agnostic...

This applies to WPF or Winforms, but out of curiousity, which are you using?

Rob Fonseca-Ensor
winform and I see what you are saying, I think. It would tie my object too tightly I suppose.
Refracted Paladin
+2  A: 

you could go for capturing the StackTrace, eg.

var methodBase = new StackTrace().GetFrame(1/* depends on your depth*/).GetMethod();
var reflecedType = methodBase.ReflectedType;
var methodName = methodBase.Name;
Andreas Niedermair