private void BtnExtractContent_Click(object sender, RoutedEventArgs e) { var Row = ((FrameworkElement)e.OriginalSource).GetNearestVisualDominantOfType <ListBoxItem>(); if (Row == null || Row.Content == null) { return; } var SelectedEditCard = Row.Content as DetailEditingCard; if (SelectedEditCard == null) { return; } var Annex = SelectedEditCard.DetailContent as Attachment; if (Annex != null) { this.SourceEngine.ExportAttachment(Annex, this.SourceIdea); return; } var Matrix = SelectedEditCard.DetailContent as Table; if (Matrix != null) { DomainServices.ExportTableDataToFile(Matrix, null); return; } Console.WriteLine("Nothing to extract."); }