private void CloseWindow(object sender, ExecutedRoutedEventArgs e) { if (lb.Items.Count > 0) { Hide(); AppWindow win = (AppWindow)lb.SelectedItem; win.PostClose(); win.SwitchTo(); } else { Hide(); } e.Handled = true; }