示例#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
            {
            }

            AppLifeCycleViewModel lifeCycle = null;

            try
            {
                lifeCycle = new AppLifeCycleViewModel();

                // Construct Application ViewMOdel and mainWindow
                _appVM = new ViewModels.AppViewModel(lifeCycle);
            }
            catch (Exception exp)
            {
                Debug.WriteLine(exp.Message);
            }

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

            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();
            }
        }
示例#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.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 = new MainWindow();
            MainWindow.DataContext         = _appVM;

            AppCore.CreateAppDataFolder();

            if (MainWindow != null && _appVM != null)
            {
                // and show it to the user ...
                //MainWindow.Loaded += MainWindow_Loaded;
                WeakEventManager <FrameworkElement, RoutedEventArgs>
                .AddHandler(MainWindow, "Loaded", MainWindow_Loaded);

                //MainWindow.Closing += OnClosing;
                WeakEventManager <Window, CancelEventArgs>
                .AddHandler(MainWindow, "Closing", OnClosing);

                // When the ViewModel asks to be closed, close the window.
                // Source: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
                WeakEventManager <Window, EventArgs>
                .AddHandler(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();
            }
        }
示例#3
0
        /// <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);
            }
        }
示例#4
0
        /// <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
            {
            }

            AppLifeCycleViewModel lifeCycle = null;
            AppViewModel          app       = null;
            var settings = GetService <ISettingsManager>();

            try
            {
                // Create a general settings model to make sure the app is at least governed by default settings
                // if there are no customized settings on first ever start-up of application
                SettingDefaults.CreateGeneralSettings(settings);
                settings.Options.SetUndirty();

                lifeCycle = new AppLifeCycleViewModel();
                lifeCycle.LoadConfigOnAppStartup();       // Load application configuration

                var selectedLanguage = settings.Options.GetOptionValue <string>("Options", "LanguageSelected");
                Thread.CurrentThread.CurrentCulture   = new CultureInfo(selectedLanguage);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);

                app = new AppViewModel(lifeCycle);
            }
            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)
                        {
                            Workspace.Dispose();
                            Workspace = null;
                        }
                    };

                    ConstructMainWindowSession(app, mMainWin);
                    mMainWin.Show();
                }
            }
            catch (Exception exp)
            {
                Logger.Error(exp);
            }
        }
示例#5
0
        /// <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);
            }
        }