private void Close_Click(object sender, RoutedEventArgs e) { var windowObject = this.DataContext as TaskBarItem; if (windowObject != null && windowObject._openWindows.Count > 0) windowObject.CloseWindow(); }