Esempio n. 1
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.Message);
            }

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

                Thread.CurrentThread.CurrentCulture   = new CultureInfo(selectedLanguage);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);
            }
            catch
            {
            }

            // 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 ...
            _appVM.InitForMainWindow(GetService <IAppearanceManager>()
                                     , settings.Options.GetOptionValue <string>("Appearance", "ThemeDisplayName"));

            Application.Current.MainWindow = _mainWindow;
            MainWindow.DataContext         = _appVM;

            AppCore.CreateAppDataFolder();

            if (MainWindow != null && _appVM != null)
            {
                // 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;
                };

                ConstructMainWindowSession(_appVM, _mainWindow);
                MainWindow.Show();
            }
        }
Esempio n. 2
0
 public App()
 {
     _mainWindow = new Views.MainWindow();
 }