Пример #1
0
        private void TemaToggleButton_Unchecked(object sender, RoutedEventArgs e)
        {
            Theme theme = (Theme)ResourceDictionaryExtensions.GetTheme(Application.Current.Resources);

            ThemeExtensions.SetBaseTheme(theme, Theme.Light);
            ResourceDictionaryExtensions.SetTheme(Application.Current.Resources, theme);
        }
Пример #2
0
        /// <summary>
        /// Switches the theme to the data provided in the color object
        /// </summary>
        public static void SwitchTheme()
        {
            IBaseTheme baseTheme    = Theme.Light;
            ITheme     defaultTheme = Theme.Create(baseTheme, Color.FromRgb(147, 91, 249), Color.FromRgb(114, 124, 245));

            ResourceDictionaryExtensions.SetTheme(Application.Current.Resources, defaultTheme);
            return;
        }
Пример #3
0
 public MainWindow()
 {
     this.DataContext = new MainWindowVistaModelo();
     InitializeComponent();
     if ((DataContext as MainWindowVistaModelo).CompruebaModoOscuro())
     {
         Theme theme = (Theme)ResourceDictionaryExtensions.GetTheme(Application.Current.Resources);
         ThemeExtensions.SetBaseTheme(theme, Theme.Dark);
         ResourceDictionaryExtensions.SetTheme(Application.Current.Resources, theme);
     }
     else
     {
         Theme theme = (Theme)ResourceDictionaryExtensions.GetTheme(Application.Current.Resources);
         ThemeExtensions.SetBaseTheme(theme, Theme.Light);
         ResourceDictionaryExtensions.SetTheme(Application.Current.Resources, theme);
     }
 }
Пример #4
0
        /// <summary>
        /// Switches the theme via some resource dictionary hackery
        /// </summary>
        /// <param name="primaryColor">Primary color brush</param>
        /// <param name="secondaryColor">Secondary color brush</param>
        /// <param name="darkMode">Application theme</param>
        public static void SwitchTheme(string primaryColor, string secondaryColor, bool darkMode)
        {
            try
            {
                IBaseTheme baseTheme = darkMode ? Theme.Dark : Theme.Light;

                Color pColor = primaryColor == "Default" ? Color.FromRgb(147, 91, 249) : (Color)ColorConverter.ConvertFromString(primaryColor);
                Color sColor = primaryColor == "Default" ? Color.FromRgb(114, 124, 245) : (Color)ColorConverter.ConvertFromString(secondaryColor);

                ITheme theme = Theme.Create(baseTheme, pColor, sColor);

                ResourceDictionaryExtensions.SetTheme(Application.Current.Resources, theme);
            }
            catch (Exception e)
            {
                logger.Write(e.ToString());
                MessageBox.Show("Something went wrong when processing theme settings, please report this exception, and the log file to LightVPN support.", "LightVPN", MessageBoxButton.OK, MessageBoxImage.Error);
                Application.Current.Shutdown();
                return;
            }
        }
Пример #5
0
 public static void ChangeTheme(IBaseTheme theme, Color primary, Color secondary)
 {
     ResourceDictionaryExtensions.SetTheme(Application.Current.Resources, Theme.Create(theme, primary, secondary));
 }
Пример #6
0
        private void _settingsViewModel_SaveRequested()
        {
            if (CurrentViewModel == _settingsViewModel) // event is fired automatically when leaving settingsview, and sets toggle on false. We have to check wether we are in settings or not (if we're not, ignore the request).
            {
                Properties.Settings.Default.idleTime    = _settingsViewModel.IdleTime;
                Properties.Settings.Default.isDarkTheme = _settingsViewModel.IsDarkTheme;
                Properties.Settings.Default.Save();

                if (!_settingsViewModel.IsDarkTheme)
                {
                    var dict = Application.Current.Resources.MergedDictionaries.First(c => ResourceDictionaryExtensions.GetName(c) == "ColorTheme");
                    dict.Source = new Uri("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml");
                }
                else
                {
                    var dict = Application.Current.Resources.MergedDictionaries.First(c => ResourceDictionaryExtensions.GetName(c) == "ColorTheme");
                    dict.Source = new Uri("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml");
                }

                MessageHandler.InvokeSuccessMessage(Properties.Resources.Environment, Properties.Resources.ChangesAutoSaved);
            }
        }
Пример #7
0
        public MainWindowViewModel()
        {
            //https://stackoverflow.com/questions/520115/stringformat-localization-issues-in-wpf/520334#520334
            FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

            try
            {
                //https://www.youtube.com/watch?v=5MuN6VOw9r4 + https://www.youtube.com/watch?v=BK7jp3snwCQ

                switch (ci.TwoLetterISOLanguageName)
                {
                case "nl":
                    Properties.Resources.Culture = new CultureInfo("nl-BE");
                    break;

                case "en":
                default:
                    Properties.Resources.Culture = new CultureInfo("en-GB");
                    break;
                }

                InitializeDatabase();


                if (!Properties.Settings.Default.isDarkTheme)
                {
                    var dict = Application.Current.Resources.MergedDictionaries.First(c => ResourceDictionaryExtensions.GetName(c) == "ColorTheme");
                    dict.Source = new Uri("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml");
                }
                else
                {
                    var dict = Application.Current.Resources.MergedDictionaries.First(c => ResourceDictionaryExtensions.GetName(c) == "ColorTheme");
                    dict.Source = new Uri("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml");
                }

                InactiveTimerHandler.TimerInvokeRequested += LogoutTimerHandler_TimerInvokeRequested;

                InitializeErrorMessageHandling();
                InitializeMessageHandling();
                SetViewModelLogin();

                _currentViewModel          = _loginViewModel;
                CurrentViewModelColumn     = 0;
                CurrentViewModelColumnSpan = 2;

                _checkInactivity          = new Timer();
                _checkInactivity.Interval = 10;

                _checkInactivity.Elapsed += CheckInactivity_Elapsed;

                ViewModelHistory = new List <BaseViewModel>();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }