private void Window_Loaded(object sender, RoutedEventArgs e) { try { ComboBoxOffice.ItemsSource = ClassSqlCalendar.ListOfAvailableOfficeForSelectedDay(calendar.CalendarDayId); if (ComboBoxOffice.Items.Count == 0) { throw new Exception("No available office for selected day \nContact with doctor needed"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); this.Close(); } }