Esempio n. 1
0
        protected override async void OnStartup(object sender, StartupEventArgs e)
        {
            var startupTasks =
                GetAllInstances(typeof(StartupTask))
                .Cast <ExportedDelegate>()
                .Select(exportedDelegate => (StartupTask)exportedDelegate.CreateDelegate(typeof(StartupTask)));

            startupTasks.Apply(s => s());
            base.OnStartup(sender, e);
            await NatHelper.DiscoverAsync();

            ThemeManager.AddAppTheme("CobaltLight", new Uri("pack://application:,,,/Themes/CobaltLight.xaml"));
            ThemeManager.AddAppTheme("CobaltDark", new Uri("pack://application:,,,/Themes/CobaltDark.xaml"));
            ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.Accents.First(a => a.Name == "Blue"),
                                        ThemeManager.GetAppTheme("CobaltLight"));
        }
Esempio n. 2
0
        public void SetTheme(Theme newTheme)
        {
            // Change app style to the custom accent and current theme
            var accent = MahAppsThemeManager.GetAccent(CustomAccentKey);
            var theme  = MahAppsThemeManager.GetAppTheme(newTheme.Style == Style.Light ? "BaseLight" : "BaseDark");

            // Modify resource values to new theme values

            // Set accent colors
            if (accent.Resources.Contains(AccentBaseColorKey))
            {
                // Set base accent color
                accent.Resources[AccentBaseColorKey] = newTheme.AccentBaseColor.ToMediaColor();


                // Set other accent colors with reduced transparency

                // Set 80% transparency accent color
                if (accent.Resources.Contains(AccentColor1Key))
                {
                    accent.Resources[AccentColor1Key] = newTheme.AccentBaseColor.SetTransparencyFraction(0.8).ToMediaColor();
                }

                // Set 60% transparency accent color
                if (accent.Resources.Contains(AccentColor2Key))
                {
                    accent.Resources[AccentColor2Key] = newTheme.AccentBaseColor.SetTransparencyFraction(0.6).ToMediaColor();
                }

                // Set 40% transparency accent color
                if (accent.Resources.Contains(AccentColor3Key))
                {
                    accent.Resources[AccentColor3Key] = newTheme.AccentBaseColor.SetTransparencyFraction(0.4).ToMediaColor();
                }

                // Set 20% transparency accent color
                if (accent.Resources.Contains(AccentColor4Key))
                {
                    accent.Resources[AccentColor4Key] = newTheme.AccentBaseColor.SetTransparencyFraction(0.2).ToMediaColor();
                }
            }

            // Set highlight color
            if (accent.Resources.Contains(HighlightColorKey))
            {
                accent.Resources[HighlightColorKey] = newTheme.HighlightColor.ToMediaColor();
            }

            // Set window border color
            if (accent.Resources.Contains(WindowBorderColorKey))
            {
                accent.Resources[WindowBorderColorKey] = newTheme.WindowBorderColor.ToMediaColor();

                // Set 80% transparency window border color
                if (accent.Resources.Contains(WindowBorderColor2Key))
                {
                    accent.Resources[WindowBorderColor2Key] = newTheme.WindowBorderColor.SetTransparencyFraction(0.8).ToMediaColor();
                }
            }

            MahAppsThemeManager.ChangeAppStyle(Application.Current, accent, theme);

            this.CurrentTheme = newTheme;
        }