예제 #1
0
 /// <summary>
 /// Class constructor
 /// </summary>
 public App()
 {
     _mainWindow  = new MainWindow();
     _appVM       = new ViewModels.AppViewModel(new AppLifeCycleViewModel());
     LayoutLoaded = new LayoutLoader(@".\AvalonDock.Layout.config");
 }
예제 #2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            try
            {
                // Set shutdown mode here (and reset further below) to enable showing custom dialogs (messageboxes)
                // durring start-up without shutting down application when the custom dialogs (messagebox) closes
                ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
            }
            catch
            {
            }

            var settings   = GetService <ISettingsManager>(); // add the default themes
            var appearance = GetService <IAppearanceManager>();
            AppLifeCycleViewModel lifeCycle = null;

            try
            {
                lifeCycle = new AppLifeCycleViewModel();
                lifeCycle.LoadConfigOnAppStartup(settings, appearance);

                appearance.SetTheme(settings.Themes
                                    , settings.Options.GetOptionValue <string>("Appearance", "ThemeDisplayName")
                                    , ThemeViewModel.GetCurrentAccentColor(settings));

                // Construct Application ViewMOdel and mainWindow
                _appVM = new ViewModels.AppViewModel(lifeCycle);
                _appVM.SetSessionData(settings.SessionData);

                // Customize services specific items for this application
                // Program message box service for Modern UI (Metro Light and Dark)
                //                var msgBox = GetService<IMessageBoxService>();
                //                msgBox.Style = MsgBoxStyle.WPFThemed;
            }
            catch (Exception exp)
            {
                Debug.WriteLine(exp);
            }

            try
            {
                var selectedLanguage = settings.Options.GetOptionValue <string>("Options", "LanguageSelected");

                Thread.CurrentThread.CurrentCulture   = new CultureInfo(selectedLanguage);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);
            }
            catch (Exception exp)
            {
                Debug.WriteLine(exp);
            }

            // Create the optional appearance viewmodel and apply
            // current settings to start-up with correct colors etc...
            ////var appearSettings = new AppearanceViewModel(settings.Themes);
            ////appearSettings.ApplyOptionsFromModel(settings.Options);

            // Initialize WPF theming and friends ...
            var defaultTheme = settings.Options.GetOptionValue <string>("Appearance", "ThemeDisplayName");

            _appVM.InitForMainWindow(appearance, defaultTheme);

            Application.Current.MainWindow = _mainWindow = new MainWindow();
            MainWindow.DataContext         = _appVM;

            AppCore.CreateAppDataFolder();

            if (MainWindow != null && _appVM != null)
            {
                ConstructMainWindowSession(_appVM, _mainWindow);

                // and show it to the user ...
                MainWindow.Loaded  += MainWindow_Loaded;
                MainWindow.Closing += OnClosing;

                // When the ViewModel asks to be closed, close the window.
                // Source: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
                MainWindow.Closed += delegate
                {
                    // Save session data and close application
                    OnClosed(_appVM, _mainWindow);

                    var dispose = _appVM as IDisposable;
                    if (dispose != null)
                    {
                        dispose.Dispose();
                    }

                    _mainWindow.DataContext = null;
                    _appVM      = null;
                    _mainWindow = null;
                };

                MainWindow.Show();
            }
        }