Beispiel #1
0
        public App()
        {
            IDisposable disposableViewModel = null;

            //Create and show window while storing datacontext
            this.Startup += (sender, args) =>
            {
                MainWindow          = new View.MainWindow();
                disposableViewModel = MainWindow.DataContext as IDisposable;

                var mvm = new MainViewModel(MainWindow);
                MainWindow.DataContext = mvm;

                MainWindow.Show();
            };

            //Dispose on unhandled exception
            this.DispatcherUnhandledException += (sender, args) =>
            {
                if (disposableViewModel != null)
                {
                    disposableViewModel.Dispose();
                }
            };

            //Dispose on exit
            this.Exit += (sender, args) =>
            {
                if (disposableViewModel != null)
                {
                    disposableViewModel.Dispose();
                }
            };
        }
        public App()
        {
            IDisposable disposableViewModel = null;

            //Create and show window while storing datacontext
            this.Startup += (sender, args) =>
            {
                MainWindow = new View.MainWindow();
                disposableViewModel = MainWindow.DataContext as IDisposable;

                var mvm = new MainViewModel(MainWindow);
                MainWindow.DataContext = mvm;

                MainWindow.Show();
            };

            //Dispose on unhandled exception
            this.DispatcherUnhandledException += (sender, args) =>
            {
                if (disposableViewModel != null) disposableViewModel.Dispose();
            };

            //Dispose on exit
            this.Exit += (sender, args) =>
            {
                if (disposableViewModel != null) disposableViewModel.Dispose();
            };
        }