WPF Controls are divided into various baskets. Some controls belong to System.Windows.Controls namespace and other belong to Panel and other stuff. I am interested in getting the control as a Panel or Control type so I can change the Background property. The following code is not working:
var element = ((sender as Panel) ?? (sender as Control));
Unfortunately, the “magical” var keyword is still statically (at compile time) resolved, what you might be thinking of is the new
dynamicC# 4.0 keyword.Otherwise, there’s no other way to do it other than