public MainWindow() {
      var vm = new MainWindowViewModel(this.Dispatcher);
      this.DataContext = vm;

      this.InitializeComponent();

      this.PreviewKeyDown += (sender, e) => (this.DataContext as IKeyHandler).HandlePreviewKeyDown(sender, e);

      this.Title = string.Format("{0} {1}", this.Title, Assembly.GetExecutingAssembly().GetName().Version);

      this.SourceInitialized += (sender, e) => this.FitIntoScreen();

      this.Closed += (sender, e) => {
                       foreach (var w in Application.Current.Windows.OfType<Window>()) {
                         w.Close();
                       }
                       var mainWindowViewModel = ((MainWindowViewModel)this.DataContext);
                       if (mainWindowViewModel.PlaylistsViewModel.FileSearchWorker.CanStopSearch()) {
                         mainWindowViewModel.PlaylistsViewModel.FileSearchWorker.StopSearch();
                       }
                       mainWindowViewModel.SaveSettings();
                       mainWindowViewModel.PlaylistsViewModel.SavePlayList();
                       PlayerEngine.Instance.CleanUp();
                     };
    }
        public MainWindow()
        {
            var vm = new MainWindowViewModel(this.Dispatcher);
              this.DataContext = vm;

              this.InitializeComponent();

              this.PreviewKeyDown += this.MainWindow_PreviewKeyDown;

              this.Title = string.Format("{0} {1}", this.Title, Assembly.GetExecutingAssembly().GetName().Version);

              this.Closed += (sender, e) => {
            ((MainWindowViewModel)this.DataContext).SaveSettings();
            PlayerEngine.Instance.CleanUp();
              };
        }