private void ButOK_Click(object sender, RoutedEventArgs e) { DateTime?begin = DpBegin.SelectedDate, end = DpEnd.SelectedDate; if (begin != null && end != null) { Vac.BeginDate = begin.Value; Vac.EndDate = end.Value; } Vac.UpdateVacation(ConnStr); var wnd = this.Parent as Window; wnd.Close(); }