Exemple #1
0
        } // end method ComboBoxExcelFileFormat_OnSelectionChanged

        // Update the theme setting if necessary.
        private void ComboBoxTheme_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ComboBoxTheme.SelectedItem == null)
                return;

            var selectedTheme = ((ComboBoxItemAdv) ComboBoxTheme.SelectedItem).Content.Equals(Properties.Resources.ComboBoxItemMaterialDark_Content)
                    ? (int) VisualStyles.MaterialDark
                    : (int) VisualStyles.MaterialLight;

            if (selectedTheme == Properties.Settings.Default.AppTheme)
                return;

            var appRestartConfirmationDialogueResult = new AppRestartConfirmationDialogue(Properties.Resources.ThemeSetting) { Owner = this }.ShowDialog();

            if (appRestartConfirmationDialogueResult == null || !(bool) appRestartConfirmationDialogueResult)
            {
                ComboBoxTheme.SelectedItem = selectedTheme == (int) VisualStyles.MaterialLight
                    ? ComboBoxItemMaterialDark
                    : ComboBoxItemMaterialLight;
                return;
            } // end if

            try
            {
                Properties.Settings.Default.AppTheme = selectedTheme;
            }
            catch (InvalidCastException)
            {
                /*
                 * The application needs restarting to refresh resources and theme configurations to apply a theme. It is necessary to change the values of some properties before restarting.
                 * However, the code in the try clause can cause changing the theme before restarting (MVVM), which may throw an exception due to missing the relevant resources.
                 * This exception can be ignored, and it should not affect changing the theme after restarting.
                 */
            } // end try...catch

            if (Properties.Settings.Default.AppTheme == (int) VisualStyles.MaterialDark)
            {
                Properties.Settings.Default.AboutIconUri = Properties.DefaultUserSettings.Default.AboutIconUri_MaterialDark;
                Properties.Settings.Default.SearchIconUri = Properties.DefaultUserSettings.Default.SearchIconUri_MaterialDark;
                Properties.Settings.Default.ClearSelectionIconUri = Properties.DefaultUserSettings.Default.ClearSelectionIconUri_MaterialDark;
                Properties.Settings.Default.RestoreColumnWidthIconUri = Properties.DefaultUserSettings.Default.RestoreColumnWidthIconUri_MaterialDark;
                Properties.Settings.Default.ExportToExcelIconUri = Properties.DefaultUserSettings.Default.ExportToExcelIconUri_MaterialDark;
                Properties.Settings.Default.PrintIconUri = Properties.DefaultUserSettings.Default.PrintIconUri_MaterialDark;
            }
            else
            {
                Properties.Settings.Default.AboutIconUri = Properties.DefaultUserSettings.Default.AboutIconUri_MaterialLight;
                Properties.Settings.Default.SearchIconUri = Properties.DefaultUserSettings.Default.SearchIconUri_MaterialLight;
                Properties.Settings.Default.ClearSelectionIconUri = Properties.DefaultUserSettings.Default.ClearSelectionIconUri_MaterialLight;
                Properties.Settings.Default.RestoreColumnWidthIconUri = Properties.DefaultUserSettings.Default.RestoreColumnWidthIconUri_MaterialLight;
                Properties.Settings.Default.ExportToExcelIconUri = Properties.DefaultUserSettings.Default.ExportToExcelIconUri_MaterialLight;
                Properties.Settings.Default.PrintIconUri = Properties.DefaultUserSettings.Default.PrintIconUri_MaterialLight;
            } // end if...else

            Restart();
        } // end method ComboBoxTheme_OnSelectionChanged
Exemple #2
0
        } // end method ComboBoxDayVolumeUnit_OnSelectionChanged

        // Update the display font family name setting if necessary.
        private void ComboBoxDisplayFontFamilyName_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ComboBoxDisplayFontFamilyName.SelectedItem == null)
                return;

            if (ComboBoxDisplayFontFamilyName.SelectedItem.Equals(Properties.Settings.Default.DisplayFontFamilyName))
                return;

            var appRestartConfirmationDialogueResult = new AppRestartConfirmationDialogue(Properties.Resources.DisplayFontFamilyNameSetting) { Owner = this }.ShowDialog();

            if (appRestartConfirmationDialogueResult == null || !(bool) appRestartConfirmationDialogueResult)
            {
                ComboBoxDisplayFontFamilyName.SelectedItem = Properties.Settings.Default.DisplayFontFamilyName;
                return;
            } // end if

            Properties.Settings.Default.DisplayFontFamilyName = (string)ComboBoxDisplayFontFamilyName.SelectedItem;
            Restart();
        } // end method ComboBoxDisplayFontFamilyName_OnSelectionChanged