/// <summary> /// This is the first bit of code being executed when the application is invoked (main entry point). /// /// Use the <paramref name="e"/> parameter to evaluate command line options. /// Invoking a program with an associated file type extension (eg.: *.txt) in Explorer /// results, for example, in executing this function with the path and filename being /// supplied in <paramref name="e"/>. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> 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 try // Program message box service for Modern UI (Metro Light and Dark) { var msgBox = GetService <IMessageBoxService>(); msgBox.Style = MsgBoxStyle.WPFThemed; // Add theming models settings.Themes.AddThemeInfo("dark", new Uri("/LocultMetro;component/Themes/ModernUIDark.xaml", UriKind.RelativeOrAbsolute)); // AppearanceManager.DarkThemeSource ); settings.Themes.AddThemeInfo("light", new Uri("/LocultMetro;component/Themes/ModernUILight.xaml", UriKind.RelativeOrAbsolute)); // AppearanceManager.LightThemeSource } catch { } // Create a general settings model to make sure the app is at least governed by defaults // if there are no customized settings on first ever start-up of application var options = settings.Options; SettingDefaults.CreateGeneralSettings(settings); MetroSettingsDefaults.CreateAppearanceSettings(options, settings); settings.Options.SetUndirty(); AppLifeCycleViewModel lifeCycle = null; AppViewModel app = null; try { lifeCycle = new AppLifeCycleViewModel(); lifeCycle.LoadConfigOnAppStartup(); var selectedLanguage = settings.Options.GetOptionValue <string>("Options", "LanguageSelected"); Thread.CurrentThread.CurrentCulture = new CultureInfo(selectedLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage); app = new AppViewModel(lifeCycle); if (settings.Options.GetOptionValue <string>("Appearance", "ThemeDisplayName") == "dark") { AppearanceManager.Current.DarkThemeCommand.Execute(null); } else { settings.Options.SetOptionValue("Appearance", "ThemeDisplayName", "light"); AppearanceManager.Current.LightThemeCommand.Execute(null); } } catch (Exception exp) { Logger.Error(exp); } // Create the optional appearance viewmodel and apply // current settings to start-up with correct colors etc... var appearSettings = new AppearanceViewModel(settings.Themes); try { appearSettings.ApplyOptionsFromModel(settings.Options); } catch (Exception exp) { Logger.Error(exp); } try { // Register this settings page viewmodel and view var reslocService = GetService <IResourceLocator>(); app.PageManager.AddSettingsPageViewModel(reslocService.GetNewPageTemplateModel( Assembly.GetAssembly(typeof(SettingsAppearance)).GetName().Name, "Views/DataTemplates.xaml", "AppAppearanceSettingsTemplate", appearSettings, "Appearance", 1000)); } catch (Exception exp) { Logger.Error(exp); } try { Application.Current.MainWindow = mMainWin = new MainWindow(); ShutdownMode = System.Windows.ShutdownMode.OnLastWindowClose; AppCore.CreateAppDataFolder(); if (mMainWin != null && app != null) { mMainWin.Loaded += mMainWin_Loaded; mMainWin.Closing += OnClosing; // When the ViewModel asks to be closed, close the window. // Source: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx mMainWin.Closed += delegate { // Save session data and close application OnClosed(Workspace, mMainWin); var dispose = Workspace as IDisposable; if (dispose != null) { dispose.Dispose(); Workspace = null; } }; ConstructMainWindowSession(app, mMainWin); mMainWin.Show(); } double fontSize = (double)settings.Options.GetOptionValue <int>("Appearance", "DefaultFontSize"); double keyFixedFontSize = (double)settings.Options.GetOptionValue <int>("Appearance", "FixedFontSize"); Application.Current.Resources[AppearanceManager.KeyDefaultFontSize] = fontSize; Application.Current.Resources[AppearanceManager.KeyFixedFontSize] = keyFixedFontSize; } catch (Exception exp) { Logger.Error(exp); } }
/// <summary> /// This is the first bit of code being executed when the application is invoked (main entry point). /// /// Use the <paramref name="e"/> parameter to evaluate command line options. /// Invoking a program with an associated file type extension (eg.: *.txt) in Explorer /// results, for example, in executing this function with the path and filename being /// supplied in <paramref name="e"/>. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> 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 try { // 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; // Add theming models settings.Themes.AddThemeInfo("dark", new Uri("/SettingsModelWPFDemo;component/Themes/DarkTheme.xaml", UriKind.RelativeOrAbsolute)); // AppearanceManager.DarkThemeSource ); settings.Themes.AddThemeInfo("light", new Uri("/SettingsModelWPFDemo;component/Themes/LightTheme.xaml", UriKind.RelativeOrAbsolute)); // AppearanceManager.LightThemeSource // Create a general settings model to make sure the app is at least governed by defaults // if there are no customized settings on first ever start-up of application var options = settings.Options; SettingDefaults.CreateGeneralSettings(options); SettingDefaults.CreateAppearanceSettings(options, settings); settings.Options.SetUndirty(); } catch { } AppLifeCycleViewModel lifeCycle = null; AppViewModel app = null; try { lifeCycle = new AppLifeCycleViewModel(); lifeCycle.LoadConfigOnAppStartup(); var selectedLanguage = settings.Options.GetOptionValue <string>("Options", "LanguageSelected"); try { Thread.CurrentThread.CurrentCulture = new CultureInfo(selectedLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage); } catch { } app = new AppViewModel(lifeCycle, settings.Options.GetOptionValue <bool>("Options", "ReloadOpenFilesFromLastSession"), settings.SessionData.LastActiveSolution); if (settings.Options.GetOptionValue <string>("Appearance", "ThemeDisplayName") == "Dark") { AppearanceManager.Current.DarkThemeCommand.Execute(null); } else { AppearanceManager.Current.LightThemeCommand.Execute(null); } // 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); } catch (Exception exp) { Logger.Error(exp); } try { Application.Current.MainWindow = mMainWin = new MainWindow(); ShutdownMode = System.Windows.ShutdownMode.OnLastWindowClose; AppCore.CreateAppDataFolder(); if (mMainWin != null && app != null) { mMainWin.Closing += OnClosing; // When the ViewModel asks to be closed, close the window. // Source: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx mMainWin.Closed += delegate { // Save session data and close application OnClosed(Workspace, mMainWin); var dispose = Workspace as IDisposable; if (dispose != null) { dispose.Dispose(); Workspace = null; } }; ConstructMainWindowSession(app, mMainWin); mMainWin.Show(); } } catch (Exception exp) { Logger.Error(exp); } }