private void MenuItem_Click_JobTreeView(object sender, RoutedEventArgs e) { MenuItem item = (MenuItem)e.Source; string tag = (string)item.Tag; IJob job = (IJob)jobTreeView.SelectedValue; if (job == null) { return; } switch (tag) { case "Abort": job.Abort(); break; default: throw new Exception(); } }