title: C# and WPF: Is it possible to make an automatic downcast of the sender argument based on its type inside an event handler?
body: <p>Usually, I know what kind of specific control raises a certain event so I can make, inside the event handler, a reference to it by a manual downcast of its sender parameter like this (assuming that sender is a Button):</p>
  
  <pre><code>var refToSender = (Button)sender;
  </code></pre>
  
  <p>Now, if for any reasons I cannot know the exact type of the sender, is it possible to make an automatic downcast without the necessity of using conditional blocks? In other words, is there the possibility to write something like this:</p>
  
  <pre><code>var refToUnknownSender = (Magic_here)sender;
  </code></pre>