public void updateSoftware(object sender, RoutedEventArgs e) { Button button = sender as Button; Software sub = button.DataContext as Software; foreach (Software s in MainWindow.softwares) { if (s.label.Equals(sub.label)) { MainWindow.softwareToUpdate = s; UpdateSoftware u = new UpdateSoftware(); u.ShowDialog(); } } }