This code works. But noticing the similarity between the 6th & 10th line,
void someThing_Click(object sender, RoutedEventArgs e)
{
President pres;
if (e.GetType() == typeof(MouseButtonEventArgs))
{
pres = (sender as SomeUserControl ).DataContext as President;
}
else
{
pres = (sender as MenuItem ).DataContext as President;
}
}
is there a way to shorten the code like,
Type t = (e.GetType() == typeof(MouseButtonEventArgs)) ? SomeUserControl : MenuItem;
pres = (sender as t).DataContext as President;
the code above doesn't work, just for illustration.