Inheritance: Accent
        /// <summary>
        /// </summary>
        public void Load()
        {
            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.Accent))
            {
                _styleAccent = ThemeManager.GetAccent(Properties.Settings.Default.Accent);
            }
            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.Theme))
            {
                _styleTheme = ThemeManager.GetAppTheme(Properties.Settings.Default.Theme);
            }

            _mainWindow.Accent.SelectedValue = _styleAccent.Name;

            switch (_styleTheme.Name)
            {
                case "BaseDark":
                    _mainWindow.Dark.IsChecked = true;
                    _mainWindow.Light.IsChecked = false;
                    break;

                case "BaseLight":
                    _mainWindow.Dark.IsChecked = false;
                    _mainWindow.Light.IsChecked = true;
                    break;
            }

            SetStyle();

            foreach (var accent in ThemeManager.Accents)
            {
                _mainWindow.Accent.Items.Add(accent.Name);
            }
        }
        public async Task GetInverseAppThemeReturnsNullForMissingTheme()
        {
            await TestHost.SwitchToAppThread();

            var appTheme = new AppTheme("TestTheme", new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml"));

            AppTheme theme = ThemeManager.GetInverseAppTheme(appTheme);

            Assert.Null(theme);
        }
Example #3
0
        public void SwitchTheme(AppTheme newTheme)
        {
            Tuple<MahApps.Metro.AppTheme, Accent> appStyle = ThemeManager.DetectAppStyle(Current);

            switch (newTheme) {

                case AppTheme.Light:
                    ThemeManager.ChangeAppStyle(
                        Current,
                        ThemeManager.GetAccent("Blue"),
                        ThemeManager.GetAppTheme("BaseLight"));
                    return;

                case AppTheme.Dark:
                    ThemeManager.ChangeAppStyle(
                        Current,
                        ThemeManager.GetAccent("Green"),
                        ThemeManager.GetAppTheme("BaseDark"));
                    return;

                default:
                    throw new NotImplementedException();
            }
        }
Example #4
0
 private static void OnThemeChanged(Accent newAccent, AppTheme newTheme)
 {
     SafeRaise.Raise(IsThemeChanged, Application.Current, new OnThemeChangedEventArgs() { AppTheme = newTheme, Accent = newAccent });
 }
Example #5
0
        private static void ChangeAppStyle(ResourceDictionary resources, Tuple <AppTheme, Accent> oldThemeInfo, Accent newAccent, AppTheme newTheme)
        {
            var themeChanged = false;

            if (oldThemeInfo != null)
            {
                var oldAccent = oldThemeInfo.Item2;
                if (oldAccent != null && oldAccent.Name != newAccent.Name)
                {
                    var oldAccentResource = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldAccent.Resources.Source);
                    if (oldAccentResource != null)
                    {
                        resources.MergedDictionaries.Add(newAccent.Resources);
                        var ok = resources.MergedDictionaries.Remove(oldAccentResource);

                        themeChanged = true;
                    }
                }

                var oldTheme = oldThemeInfo.Item1;
                if (oldTheme != null && oldTheme != newTheme)
                {
                    var oldThemeResource = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldTheme.Resources.Source);
                    if (oldThemeResource != null)
                    {
                        resources.MergedDictionaries.Add(newTheme.Resources);
                        var ok = resources.MergedDictionaries.Remove(oldThemeResource);

                        themeChanged = true;
                    }
                }
            }
            else
            {
                ChangeAppStyle(resources, newAccent, newTheme);

                themeChanged = true;
            }

            if (themeChanged)
            {
                OnThemeChanged(newAccent, newTheme);
            }
        }
Example #6
0
        public static void ChangeAppStyle(ResourceDictionary resources, Accent newAccent, AppTheme newTheme)
        {
            if (resources == null) throw new ArgumentNullException("resources");

            ApplyResourceDictionary(newAccent.Resources, resources);
            ApplyResourceDictionary(newTheme.Resources, resources);
        }
Example #7
0
        private static bool DetectThemeFromResources(ref AppTheme detectedTheme, ResourceDictionary dict)
        {
            var enumerator = dict.MergedDictionaries.GetEnumerator();
            while (enumerator.MoveNext())
            {
                var currentRd = enumerator.Current;

                AppTheme matched = null;
                if ((matched = GetAppTheme(currentRd)) != null)
                {
                    detectedTheme = matched;
                    enumerator.Dispose();
                    return true;
                }

                if (DetectThemeFromResources(ref detectedTheme, currentRd))
                {
                    return true;
                }
            }

            enumerator.Dispose();
            return false;
        }
Example #8
0
        /// <summary>
        /// Gets the inverse <see cref="AppTheme" /> of the given <see cref="AppTheme"/>.
        /// This method relies on the "Dark" or "Light" affix to be present.
        /// </summary>
        /// <param name="appTheme">The app theme.</param>
        /// <returns>The inverse <see cref="AppTheme"/> or <c>null</c> if it couldn't be found.</returns>
        /// <remarks>
        /// Returns BaseLight, if BaseDark is given or vice versa.
        /// Custom Themes must end with "Dark" or "Light" for this to work, for example "CustomDark" and "CustomLight".
        /// </remarks>
        public static AppTheme GetInverseAppTheme(AppTheme appTheme)
        {
            if (appTheme == null)
                throw new ArgumentNullException("appTheme");

            if (appTheme.Name.EndsWith("dark", StringComparison.InvariantCultureIgnoreCase))
            {
                return GetAppTheme(appTheme.Name.ToLower().Replace("dark", String.Empty) + "light");
            }

            if (appTheme.Name.EndsWith("light", StringComparison.InvariantCultureIgnoreCase))
            {
                return GetAppTheme(appTheme.Name.ToLower().Replace("light", String.Empty) + "dark");
            }

            return null;
        }
Example #9
0
        public static void ChangeAppStyle(Window window, Accent newAccent, AppTheme newTheme)
        {
            if (window == null) throw new ArgumentNullException("window");

            var oldTheme = DetectAppStyle(window);
            ChangeAppStyle(window.Resources, oldTheme, newAccent, newTheme);
        }
Example #10
0
 /// <summary>
 /// Creates a new instance of this class.
 /// </summary>
 public OnThemeChangedEventArgs(AppTheme appTheme, Accent accent)
 {
     this.AppTheme = appTheme;
     this.Accent   = accent;
 }
Example #11
0
 public void doDefault()
 {
     accent = ThemeManager.GetAccent("Steel");
     theme = ThemeManager.GetAppTheme("BaseDark");
     RaisePropertyChangedEvent("Accent");
     RaisePropertyChangedEvent("Theme");
     applyNewStyle();
 }
Example #12
0
        public static void ChangeAppStyle([NotNull] Window window, [NotNull] Accent newAccent, [NotNull] AppTheme newTheme)
        {
            if (window == null)
            {
                throw new ArgumentNullException(nameof(window));
            }
            if (newAccent == null)
            {
                throw new ArgumentNullException(nameof(newAccent));
            }
            if (newTheme == null)
            {
                throw new ArgumentNullException(nameof(newTheme));
            }

            var oldTheme = DetectAppStyle(window);

            ChangeAppStyle(window.Resources, oldTheme, newAccent, newTheme);
        }
Example #13
0
 private static void OnThemeChanged(Accent newAccent, AppTheme newTheme)
 {
     IsThemeChanged?.Invoke(Application.Current, new OnThemeChangedEventArgs(newTheme, newAccent));
 }
Example #14
0
        public static void ChangeAppStyle([NotNull] Application app, [NotNull] Accent newAccent, [NotNull] AppTheme newTheme)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (newAccent == null)
            {
                throw new ArgumentNullException(nameof(newAccent));
            }
            if (newTheme == null)
            {
                throw new ArgumentNullException(nameof(newTheme));
            }

            var oldTheme = DetectAppStyle(app);

            ChangeAppStyle(app.Resources, oldTheme, newAccent, newTheme);
        }
Example #15
0
 private void DarkButtonClick(object sender, RoutedEventArgs e)
 {
     currentTheme = ThemeManager.AppThemes.First(x => x.Name == "BaseDark");
     ThemeManager.ChangeAppStyle(Application.Current, currentAccent, currentTheme);
 }
        /// <summary>
        ///     Theme of application style.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="routedEventArgs"></param>
        public void SetTheme(object sender, RoutedEventArgs routedEventArgs)
        {
            // get the theme from the current application
            var style = ThemeManager.DetectAppStyle(Application.Current);

            var radiobutton = (RadioButton)sender;
            _styleTheme = style.Item1;

            switch (radiobutton.Name)
            {
                case "Dark":
                    _styleTheme = ThemeManager.GetAppTheme("BaseDark");
                    break;

                case "Light":
                    _styleTheme = ThemeManager.GetAppTheme("BaseLight");
                    break;

                default:
                    _styleTheme = style.Item1;
                    break;
            }

            SetStyle();
        }
 /// <summary>
 /// Sets the style of the specified <see cref="Application" /><paramref name="application" />
 /// </summary>
 /// <remarks>Miguel Santana 2015/05/03</remarks>
 /// <param name="application"></param>
 /// <param name="accentColor"></param>
 /// <param name="themeColor"></param>
 public static void ChangeAppStyle(this Application application, Accent accentColor, AppTheme themeColor = null)
 {
     ThemeManager.ChangeAppStyle(application, accentColor, themeColor ?? DefaultTheme);
 }
Example #18
0
        private static void ChangeAppStyle(ResourceDictionary resources, Tuple <AppTheme, Accent> oldThemeInfo, Accent newAccent, AppTheme newTheme)
        {
            bool flag = false;

            if (oldThemeInfo == null)
            {
                ThemeManager.ChangeAppStyle(resources, newAccent, newTheme);
                flag = true;
            }
            else
            {
                Accent item2 = oldThemeInfo.Item2;
                if (item2 != null && item2.Name != newAccent.Name)
                {
                    string             lower = item2.Resources.Source.ToString().ToLower();
                    ResourceDictionary resourceDictionaries = (
                        from x in resources.MergedDictionaries
                        where x.Source != null
                        select x).FirstOrDefault <ResourceDictionary>((ResourceDictionary d) => d.Source.ToString().ToLower() == lower);
                    if (resourceDictionaries != null)
                    {
                        resources.MergedDictionaries.Add(newAccent.Resources);
                        resources.MergedDictionaries.Remove(resourceDictionaries);
                        flag = true;
                    }
                }
                AppTheme item1 = oldThemeInfo.Item1;
                if (item1 != null && item1 != newTheme)
                {
                    string             str = item1.Resources.Source.ToString().ToLower();
                    ResourceDictionary resourceDictionaries1 = (
                        from x in resources.MergedDictionaries
                        where x.Source != null
                        select x).FirstOrDefault <ResourceDictionary>((ResourceDictionary d) => d.Source.ToString().ToLower() == str);
                    if (resourceDictionaries1 != null)
                    {
                        resources.MergedDictionaries.Add(newTheme.Resources);
                        resources.MergedDictionaries.Remove(resourceDictionaries1);
                        flag = true;
                    }
                }
            }
            if (flag)
            {
                ThemeManager.OnThemeChanged(newAccent, newTheme);
            }
        }
 private void LightButtonClick(object sender, RoutedEventArgs e)
 {
     currentTheme = ThemeManager.DefaultAppThemes.First(x => x.Name == "BaseLight");
     ThemeManager.ChangeTheme(Application.Current, currentAccent, currentTheme);
 }
Example #20
0
        private static void ChangeAppStyle(ResourceDictionary resources, Tuple <AppTheme, Accent> oldThemeInfo, Accent newAccent, AppTheme newTheme)
        {
            var themeChanged = false;

            if (oldThemeInfo != null)
            {
                var oldAccent = oldThemeInfo.Element2;
                if (oldAccent != null && oldAccent.Name != newAccent.Name)
                {
                    var key = oldAccent.Resources.Source.ToString().ToLower();
                    var oldAccentResource = resources.MergedDictionaries.Where(x => x.Source != null).FirstOrDefault(d => d.Source.ToString().ToLower() == key);
                    if (oldAccentResource != null)
                    {
                        resources.MergedDictionaries.Add(newAccent.Resources);
                        resources.MergedDictionaries.Remove(oldAccentResource);

                        themeChanged = true;
                    }
                }

                var oldTheme = oldThemeInfo.Element1;
                if (oldTheme != null && oldTheme != newTheme)
                {
                    var key = oldTheme.Resources.Source.ToString().ToLower();
                    var oldThemeResource = resources.MergedDictionaries.Where(x => x.Source != null).FirstOrDefault(d => d.Source.ToString().ToLower() == key);
                    if (oldThemeResource != null)
                    {
                        resources.MergedDictionaries.Add(newTheme.Resources);
                        resources.MergedDictionaries.Remove(oldThemeResource);

                        themeChanged = true;
                    }
                }
            }
            else
            {
                ChangeAppStyle(resources, newAccent, newTheme);

                themeChanged = true;
            }

            if (themeChanged)
            {
                OnThemeChanged(newAccent, newTheme);
            }
        }
 public void InitializeThemeObject()
 {
     Light = ThemeManager.GetAppTheme("BaseLight");
     CurrentAccent = ThemeManager.GetAccent("Blue");
 }
Example #22
0
        public static void ChangeAppStyle(ResourceDictionary resources, Accent newAccent, AppTheme newTheme)
        {
            if (resources == null)
            {
                throw new ArgumentNullException("resources");
            }
            if (newAccent == null)
            {
                throw new ArgumentNullException("newAccent");
            }
            if (newTheme == null)
            {
                throw new ArgumentNullException("newTheme");
            }

            ApplyResourceDictionary(newAccent.Resources, resources);
            ApplyResourceDictionary(newTheme.Resources, resources);
        }
Example #23
0
        public static void ChangeAppStyle(Application app, Accent newAccent, AppTheme newTheme)
        {
            if (app == null) throw new ArgumentNullException("app");

            var oldTheme = DetectAppStyle(app);
            ChangeAppStyle(app.Resources, oldTheme, newAccent, newTheme);
        }
Example #24
0
        internal static bool DetectThemeFromAppResources(out AppTheme detectedTheme)
        {
            detectedTheme = null;

            return(DetectThemeFromResources(ref detectedTheme, Application.Current.Resources));
        }
Example #25
0
        private static void ChangeAppStyle(ResourceDictionary resources, Tuple<AppTheme, Accent> oldThemeInfo, Accent newAccent, AppTheme newTheme)
        {
            var themeChanged = false;
            if (oldThemeInfo != null)
            {
                var oldAccent = oldThemeInfo.Item2;
                if (oldAccent != null && oldAccent.Name != newAccent.Name)
                {
                    var oldAccentResource = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldAccent.Resources.Source);
                    if (oldAccentResource != null)
                    {
                        resources.MergedDictionaries.Add(newAccent.Resources);
                        var ok = resources.MergedDictionaries.Remove(oldAccentResource);

                        themeChanged = true;
                    }
                }

                var oldTheme = oldThemeInfo.Item1;
                if (oldTheme != null && oldTheme != newTheme)
                {
                    var oldThemeResource = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldTheme.Resources.Source);
                    if (oldThemeResource != null)
                    {
                        resources.MergedDictionaries.Add(newTheme.Resources);
                        var ok = resources.MergedDictionaries.Remove(oldThemeResource);

                        themeChanged = true;
                    }
                }
            }
            else
            {
                ChangeAppStyle(resources, newAccent, newTheme);

                themeChanged = true;
            }

            if (themeChanged)
            {
                OnThemeChanged(newAccent, newTheme);
            }
        }
Example #26
0
 private static void OnThemeChanged(Accent newAccent, AppTheme newTheme)
 {
     SafeRaise.Raise(IsThemeChanged, Application.Current, new OnThemeChangedEventArgs {
         AppTheme = newTheme, Accent = newAccent
     });
 }
Example #27
0
        internal static bool DetectThemeFromAppResources(out AppTheme detectedTheme)
        {
            detectedTheme = null;

            return DetectThemeFromResources(ref detectedTheme, Application.Current.Resources);
        }
Example #28
0
        private void OpenSettings_Click(object sender, RoutedEventArgs e)
        {
            if (!SettingsFlyout.IsOpen)
            {
                SettingsUsername.Text = getSelfName();
                SettingsStatus.Text = getSelfStatusMessage();
                SettingsNospam.Text = tox.GetNospam().ToString();

                var style = ThemeManager.DetectAppStyle(Application.Current);
                var accent = ThemeManager.GetAccent(style.Item2.Name);
                oldAccent = accent;
                if (accent != null)
                    AccentComboBox.SelectedItem = AccentComboBox.Items.Cast<AccentColorMenuData>().Single(a => a.Name == style.Item2.Name);

                var theme = ThemeManager.GetAppTheme(style.Item1.Name);
                oldAppTheme = theme;
                if (theme != null)
                    AppThemeComboBox.SelectedItem = AppThemeComboBox.Items.Cast<AppThemeMenuData>().Single(a => a.Name == style.Item1.Name);

                ViewModel.UpdateDevices();

                foreach(var item in VideoDevicesComboBox.Items)
                {
                    var device = (VideoMenuData)item;
                    if (device.Name == config.VideoDevice)
                    {
                        VideoDevicesComboBox.SelectedItem = item;
                        break;
                    }
                }

                if (InputDevicesComboBox.Items.Count - 1 >= config.InputDevice)
                    InputDevicesComboBox.SelectedIndex = config.InputDevice;

                if (OutputDevicesComboBox.Items.Count - 1 >= config.OutputDevice)
                    OutputDevicesComboBox.SelectedIndex = config.OutputDevice;

                ChatLogCheckBox.IsChecked = config.EnableChatLogging;
                HideInTrayCheckBox.IsChecked = config.HideInTray;
                PortableCheckBox.IsChecked = config.Portable;
                AudioNotificationCheckBox.IsChecked = config.EnableAudioNotifications;
                AlwaysNotifyCheckBox.IsChecked = config.AlwaysNotify;
	            SpellcheckCheckBox.IsChecked = config.EnableSpellcheck;
				SpellcheckLanguageComboBox.SelectedItem = Enum.GetName(typeof(SpellcheckLanguage), config.SpellcheckLanguage);
                FilterAudioCheckbox.IsChecked = config.FilterAudio;

                if (!string.IsNullOrEmpty(config.ProxyAddress))
                    SettingsProxyAddress.Text = config.ProxyAddress;

                if (config.ProxyPort != 0)
                    SettingsProxyPort.Text = config.ProxyPort.ToString();

                foreach (ComboBoxItem item in ProxyTypeComboBox.Items)
                {
                    if ((ToxProxyType)int.Parse((string)item.Tag) == config.ProxyType)
                    {
                        ProxyTypeComboBox.SelectedItem = item;
                        break;
                    }
                }
            }

            SettingsFlyout.IsOpen = !SettingsFlyout.IsOpen;
        }
Example #29
0
        internal static bool GetThemeFromResources(AppTheme presetTheme, ResourceDictionary dict, ref Tuple<AppTheme, Accent> detectedAccentTheme)
        {
            AppTheme currentTheme = presetTheme;

            Accent matched = null;
            if ((matched = GetAccent(dict)) != null)
            {
                detectedAccentTheme = Tuple.Create<AppTheme, Accent>(currentTheme, matched);
                return true;
            }

            foreach (ResourceDictionary rd in dict.MergedDictionaries)
            {
                if (GetThemeFromResources(presetTheme, rd, ref detectedAccentTheme))
                    return true;
            }

            return false;
        }
 /// <summary>
 /// Sets the style of the specified <see cref="Window" /><paramref name="window" />
 /// </summary>
 /// <remarks>Miguel Santana 2015/05/03</remarks>
 /// <param name="window"></param>
 /// <param name="accentColor"></param>
 /// <param name="themeColor"></param>
 public static void ChangeAppStyle(this Window window, Accent accentColor, AppTheme themeColor = null)
 {
     ThemeManager.ChangeAppStyle(window, accentColor, themeColor ?? DefaultTheme);
 }
Example #31
0
        private void OpenSettings_Click(object sender, RoutedEventArgs e)
        {
            userPressedSave = false;
            if (!SettingsFlyout.IsOpen)
            {
                SettingsUsername.Text = tox.GetSelfName();
                SettingsStatus.Text = tox.GetSelfStatusMessage();
                SettingsNospam.Text = tox.GetNospam().ToString();

                Tuple<AppTheme, Accent> style = ThemeManager.DetectAppStyle(System.Windows.Application.Current);
                Accent accent = ThemeManager.GetAccent(style.Item2.Name);
                oldAccent = accent;
                if (accent != null)
                    AccentComboBox.SelectedItem = AccentComboBox.Items.Cast<AccentColorMenuData>().Single(a => a.Name == style.Item2.Name);

                AppTheme theme = ThemeManager.GetAppTheme(style.Item1.Name);
                oldAppTheme = theme;
                if (theme != null)
                    AppThemeComboBox.SelectedItem = AppThemeComboBox.Items.Cast<AppThemeMenuData>().Single(a => a.Name == style.Item1.Name);
            }

            SettingsFlyout.IsOpen = !SettingsFlyout.IsOpen;
        }
Example #32
0
 /// <summary>
 /// Gets app theme with the given app theme and theme type (light or dark).
 /// </summary>
 /// <param name="currentAppTheme"></param>
 /// <param name="theme"></param>
 /// <returns>AppTheme</returns>
 public static AppTheme GetAppTheme(AppTheme currentAppTheme, Theme theme)
 {
     return GetAppTheme(currentAppTheme.Name, theme);
 }